Пример #1
0
 def test_markdown_vimeo(self):
     """
     markdown vimeo
     """
     comment = "https://vimeo.com/11111111\n" \
               "https://www.vimeo.com/11111111\n" \
               "https://player.vimeo.com/video/11111111\n" \
               "https://vimeo.com/channels/11111111\n" \
               "https://vimeo.com/groups/name/videos/11111111\n" \
               "https://vimeo.com/album/2222222/video/11111111\n" \
               "https://vimeo.com/11111111?param=value\n" \
               "https://novimeo.com/11111111\n" \
               "bad https://novimeo.com/11111111\n" \
               "https://novimeo.com/11111111 bad"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertListEqual(
         comment_md.splitlines(),
         '<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
         '\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
         '\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
         '\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
         '\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
         '\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
         '\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
         '\n<p><a href="https://novimeo.com/11111111">https://novimeo.com/11111111</a><br>'
         'bad <a href="https://novimeo.com/11111111">https://novimeo.com/11111111</a><br>'
         '<a href="https://novimeo.com/11111111">https://novimeo.com/11111111</a> bad</p>'
         .splitlines())
Пример #2
0
 def test_markdown_vimeo(self):
     """
     markdown vimeo
     """
     comment = "https://vimeo.com/11111111\n" \
               "https://www.vimeo.com/11111111\n" \
               "https://player.vimeo.com/video/11111111\n" \
               "https://vimeo.com/channels/11111111\n" \
               "https://vimeo.com/groups/name/videos/11111111\n" \
               "https://vimeo.com/album/2222222/video/11111111\n" \
               "https://vimeo.com/11111111?param=value\n" \
               "https://novimeo.com/11111111\n" \
               "bad https://novimeo.com/11111111\n" \
               "https://novimeo.com/11111111 bad"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertListEqual(comment_md.splitlines(), '<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
                          '\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
                          '\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
                          '\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
                          '\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
                          '\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
                          '\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
                          '\n<p><a href="https://novimeo.com/11111111">https://novimeo.com/11111111</a><br>'
                          'bad <a href="https://novimeo.com/11111111">https://novimeo.com/11111111</a><br>'
                          '<a href="https://novimeo.com/11111111">https://novimeo.com/11111111</a> bad</p>'.splitlines())
Пример #3
0
 def test_markdown_mentions_limit(self):
     """
     markdown mentions limit
     """
     comment = "@a, @b, @nitely"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertEqual(comment_md, "<p>@a, @b, @nitely</p>")
Пример #4
0
 def test_markdown_mentions_limit(self):
     """
     markdown mentions limit
     """
     comment = "@a, @b, @nitely"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertEqual(comment_md, "<p>@a, @b, @nitely</p>")
Пример #5
0
 def test_markdown_audio(self):
     """
     markdown audio
     """
     comment = "http://foo.bar/audio.mp3\nhttp://foo.bar/<escaped>.mp3"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertListEqual(comment_md.splitlines(), '<audio controls><source src="http://foo.bar/audio.mp3"><a href="http://foo.bar/audio.mp3">http://foo.bar/audio.mp3</a></audio>'
                          '\n<audio controls><source src="http://foo.bar/&lt;escaped&gt;.mp3"><a href="http://foo.bar/&lt;escaped&gt;.mp3">http://foo.bar/&lt;escaped&gt;.mp3</a></audio>'.splitlines())
Пример #6
0
 def test_markdown_emoji(self):
     """
     markdown emojify
     """
     comment = ":airplane:, :8ball: :bademoji: foo:"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertEqual(comment_md, '<p><img class="comment-emoji" src="%(static)sspirit/emojis/airplane.png">, '
                                  '<img class="comment-emoji" src="%(static)sspirit/emojis/8ball.png"> '
                                  ':bademoji: foo:</p>' % {'static': settings.STATIC_URL, })
Пример #7
0
 def test_markdown_mentions_dict(self):
     """
     markdown mentions dict
     """
     comment = "@nitely, @esteban"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     # mentions get dianmically added on MentionifyExtension
     self.assertDictEqual(md.get_mentions(), {'nitely': self.user,
                                              'esteban': self.user2})
Пример #8
0
 def test_markdown_mentions_dict(self):
     """
     markdown mentions dict
     """
     comment = "@nitely, @esteban"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     # mentions get dianmically added on MentionifyExtension
     self.assertDictEqual(md.get_mentions(), {
         'nitely': self.user,
         'esteban': self.user2
     })
Пример #9
0
 def test_markdown_video(self):
     """
     markdown video
     """
     comment = "http://foo.bar/video.mp4\nhttp://foo.bar/<escaped>.mp4"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertListEqual(comment_md.splitlines(), '<video controls><source src="http://foo.bar/video.mp4">'
                                                   '<a href="http://foo.bar/video.mp4">http://foo.bar/video.mp4</a></video>'
                                                   '\n<video controls><source src="http://foo.bar/&lt;escaped&gt;.mp4">'
                                                   '<a href="http://foo.bar/&lt;escaped&gt;.mp4">'
                                                   'http://foo.bar/&lt;escaped&gt;.mp4</a></video>'.splitlines())
Пример #10
0
 def test_markdown_audio(self):
     """
     markdown audio
     """
     comment = "http://foo.bar/audio.mp3\nhttp://foo.bar/<escaped>.mp3"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertListEqual(
         comment_md.splitlines(),
         '<audio controls><source src="http://foo.bar/audio.mp3"><a href="http://foo.bar/audio.mp3">http://foo.bar/audio.mp3</a></audio>'
         '\n<audio controls><source src="http://foo.bar/&lt;escaped&gt;.mp3"><a href="http://foo.bar/&lt;escaped&gt;.mp3">http://foo.bar/&lt;escaped&gt;.mp3</a></audio>'
         .splitlines())
Пример #11
0
 def test_markdown_mentions(self):
     """
     markdown mentions
     """
     comment = "@nitely, @esteban,@áéíóú, @fakeone"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertEqual(
         comment_md, '<p><a class="comment-mention" href="%s">@nitely</a>, '
         '<a class="comment-mention" href="%s">@esteban</a>,'
         '<a class="comment-mention" href="%s">@\xe1\xe9\xed\xf3\xfa</a>, '
         '@fakeone</p>' %
         (self.user.get_absolute_url(), self.user2.get_absolute_url(),
          self.user3.get_absolute_url()))
Пример #12
0
 def test_markdown_emoji(self):
     """
     markdown emojify
     """
     comment = ":airplane:, :8ball: :bademoji: foo:"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertEqual(
         comment_md,
         '<p><img class="comment-emoji" src="%(static)sspirit/emojis/airplane.png">, '
         '<img class="comment-emoji" src="%(static)sspirit/emojis/8ball.png"> '
         ':bademoji: foo:</p>' % {
             'static': settings.STATIC_URL,
         })
Пример #13
0
 def test_markdown_mentions(self):
     """
     markdown mentions
     """
     comment = "@nitely, @esteban,@áéíóú, @fakeone"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertEqual(comment_md, '<p><a class="comment-mention" href="%s">@nitely</a>, '
                                  '<a class="comment-mention" href="%s">@esteban</a>,'
                                  '<a class="comment-mention" href="%s">@\xe1\xe9\xed\xf3\xfa</a>, '
                                  '@fakeone</p>' %
                                  (self.user.get_absolute_url(),
                                   self.user2.get_absolute_url(),
                                   self.user3.get_absolute_url()))
Пример #14
0
 def test_markdown_video(self):
     """
     markdown video
     """
     comment = "http://foo.bar/video.mp4\nhttp://foo.bar/<escaped>.mp4"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertListEqual(
         comment_md.splitlines(),
         '<video controls><source src="http://foo.bar/video.mp4">'
         '<a href="http://foo.bar/video.mp4">http://foo.bar/video.mp4</a></video>'
         '\n<video controls><source src="http://foo.bar/&lt;escaped&gt;.mp4">'
         '<a href="http://foo.bar/&lt;escaped&gt;.mp4">'
         'http://foo.bar/&lt;escaped&gt;.mp4</a></video>'.splitlines())
Пример #15
0
 def test_markdown_youtube(self):
     """
     markdown youtube
     """
     comment = "https://www.youtube.com/watch?v=Z0UISCEe52Y\n" \
               "http://youtu.be/afyK1HSFfgw\n" \
               "https://www.youtube.com/embed/vsF0K3Ou1v0\n" \
               "https://www.youtube.com/watch?v=<bad>\n" \
               "https://www.noyoutube.com/watch?v=Z0UISCEe52Y\n" \
               "badbad https://www.youtube.com/watch?v=Z0UISCEe52Y\n" \
               "https://www.youtube.com/watch?v=Z0UISCEe52Y badbad\n"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertListEqual(comment_md.splitlines(), '<span class="video"><iframe src="https://www.youtube.com/embed/Z0UISCEe52Y?feature=oembed" allowfullscreen></iframe></span>'
                          '\n<span class="video"><iframe src="https://www.youtube.com/embed/afyK1HSFfgw?feature=oembed" allowfullscreen></iframe></span>'
                          '\n<span class="video"><iframe src="https://www.youtube.com/embed/vsF0K3Ou1v0?feature=oembed" allowfullscreen></iframe></span>'
                          '\n<p><a href="https://www.youtube.com/watch?v=&lt;bad&amp;gt">https://www.youtube.com/watch?v=&lt;bad&amp;gt</a>;<br>'  # smart_amp ain't smart
                          '<a href="https://www.noyoutube.com/watch?v=Z0UISCEe52Y">https://www.noyoutube.com/watch?v=Z0UISCEe52Y</a><br>'
                          'badbad <a href="https://www.youtube.com/watch?v=Z0UISCEe52Y">https://www.youtube.com/watch?v=Z0UISCEe52Y</a><br>'
                          '<a href="https://www.youtube.com/watch?v=Z0UISCEe52Y">https://www.youtube.com/watch?v=Z0UISCEe52Y</a> badbad</p>'.splitlines())
Пример #16
0
 def test_markdown_image(self):
     """
     markdown image
     """
     comment = "http://foo.bar/image.png\nhttp://www.foo.bar.fb/path/image.png\n" \
               "https://foo.bar/image.png\n" \
               "bad http://foo.bar/image.png\nhttp://foo.bar/image.png bad\nhttp://bad.png\n" \
               "http://foo.bar/.png\n![im](http://foo.bar/not_imagified.png)\n" \
               "foo.bar/bad.png\n\nhttp://foo.bar/<escaped>.png"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertListEqual(comment_md.splitlines(), '<p><img src="http://foo.bar/image.png" alt="image" title="image"></p>\n'
                          '<p><img src="http://www.foo.bar.fb/path/image.png" alt="image" title="image"></p>\n'
                          '<p><img src="https://foo.bar/image.png" alt="image" title="image"></p>\n'
                          '<p>bad <a href="http://foo.bar/image.png">http://foo.bar/image.png</a><br>'  # autolink
                          '<a href="http://foo.bar/image.png">http://foo.bar/image.png</a> bad<br>'  # autolink
                          '<a href="http://bad.png">http://bad.png</a><br>'  # autolink
                          '<a href="http://foo.bar/.png">http://foo.bar/.png</a><br>'  # autolink
                          '<img src="http://foo.bar/not_imagified.png" alt="im"><br>'
                          'foo.bar/bad.png</p>\n'
                          '<p><img src="http://foo.bar/&lt;escaped&gt;.png" alt="&lt;escaped&gt;" title="&lt;escaped&gt;"></p>\n'.splitlines())
Пример #17
0
 def test_markdown_youtube(self):
     """
     markdown youtube
     """
     comment = "https://www.youtube.com/watch?v=Z0UISCEe52Y\n" \
               "http://youtu.be/afyK1HSFfgw\n" \
               "https://www.youtube.com/embed/vsF0K3Ou1v0\n" \
               "https://www.youtube.com/watch?v=<bad>\n" \
               "https://www.noyoutube.com/watch?v=Z0UISCEe52Y\n" \
               "badbad https://www.youtube.com/watch?v=Z0UISCEe52Y\n" \
               "https://www.youtube.com/watch?v=Z0UISCEe52Y badbad\n"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertListEqual(
         comment_md.splitlines(),
         '<span class="video"><iframe src="https://www.youtube.com/embed/Z0UISCEe52Y?feature=oembed" allowfullscreen></iframe></span>'
         '\n<span class="video"><iframe src="https://www.youtube.com/embed/afyK1HSFfgw?feature=oembed" allowfullscreen></iframe></span>'
         '\n<span class="video"><iframe src="https://www.youtube.com/embed/vsF0K3Ou1v0?feature=oembed" allowfullscreen></iframe></span>'
         '\n<p><a href="https://www.youtube.com/watch?v=&lt;bad&amp;gt">https://www.youtube.com/watch?v=&lt;bad&amp;gt</a>;<br>'  # smart_amp ain't smart
         '<a href="https://www.noyoutube.com/watch?v=Z0UISCEe52Y">https://www.noyoutube.com/watch?v=Z0UISCEe52Y</a><br>'
         'badbad <a href="https://www.youtube.com/watch?v=Z0UISCEe52Y">https://www.youtube.com/watch?v=Z0UISCEe52Y</a><br>'
         '<a href="https://www.youtube.com/watch?v=Z0UISCEe52Y">https://www.youtube.com/watch?v=Z0UISCEe52Y</a> badbad</p>'
         .splitlines())
Пример #18
0
 def test_markdown_image(self):
     """
     markdown image
     """
     comment = "http://foo.bar/image.png\nhttp://www.foo.bar.fb/path/image.png\n" \
               "https://foo.bar/image.png\n" \
               "bad http://foo.bar/image.png\nhttp://foo.bar/image.png bad\nhttp://bad.png\n" \
               "http://foo.bar/.png\n![im](http://foo.bar/not_imagified.png)\n" \
               "foo.bar/bad.png\n\nhttp://foo.bar/<escaped>.png"
     md = Markdown(escape=True, hard_wrap=True)
     comment_md = md.render(comment)
     self.assertListEqual(
         comment_md.splitlines(),
         '<p><img src="http://foo.bar/image.png" alt="image" title="image"></p>\n'
         '<p><img src="http://www.foo.bar.fb/path/image.png" alt="image" title="image"></p>\n'
         '<p><img src="https://foo.bar/image.png" alt="image" title="image"></p>\n'
         '<p>bad <a href="http://foo.bar/image.png">http://foo.bar/image.png</a><br>'  # autolink
         '<a href="http://foo.bar/image.png">http://foo.bar/image.png</a> bad<br>'  # autolink
         '<a href="http://bad.png">http://bad.png</a><br>'  # autolink
         '<a href="http://foo.bar/.png">http://foo.bar/.png</a><br>'  # autolink
         '<img src="http://foo.bar/not_imagified.png" alt="im"><br>'
         'foo.bar/bad.png</p>\n'
         '<p><img src="http://foo.bar/&lt;escaped&gt;.png" alt="&lt;escaped&gt;" title="&lt;escaped&gt;"></p>\n'
         .splitlines())
Пример #19
0
 def _get_comment_html(self):
     markdown = Markdown(escape=True, hard_wrap=True)
     comment_html = markdown.render(self.cleaned_data['comment'])
     self.mentions = markdown.get_mentions()
     return comment_html
Пример #20
0
 def _get_comment_html(self):
     markdown = Markdown(escape=True, hard_wrap=True)
     comment_html = markdown.render(self.cleaned_data['comment'])
     self.mentions = markdown.get_mentions()
     return comment_html