You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/05/17 00:30:31 UTC

[40/50] [abbrv] git commit: [#5634] ticket:333 Use h.really_unicode and add comments

[#5634] ticket:333 Use h.really_unicode and add comments


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/fcd3b587
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/fcd3b587
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/fcd3b587

Branch: refs/heads/db/6208
Commit: fcd3b5876e810c4d269daf0844d848b420b04237
Parents: 9224324
Author: Igor Bondarenko <je...@gmail.com>
Authored: Wed May 8 14:10:17 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed May 15 15:44:04 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/markdown_extensions.py |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fcd3b587/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 62b7fe9..a1158e5 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -252,7 +252,15 @@ class RelativeLinkRewriter(markdown.postprocessors.Postprocessor):
             rewrite(link, 'href')
         for link in soup.findAll('img'):
             rewrite(link, 'src')
-        return unicode(str(soup), "utf-8" )
+        # BeautifulSoup always stores data in unicode,
+        # but when doing unicode(soup) it does some strange things
+        # like nesting html comments, e.g. returns <!--<!-- comment -->-->
+        # instead of <!-- comment -->.
+        # Converting soup object to string representation first,
+        # and then back to unicode avoids that.
+        # str() called on BeautifulSoup document always returns string
+        # encoded in utf-8, so this should always work.
+        return h.really_unicode(str(soup))
 
     def _rewrite(self, tag, attr):
         val = tag.get(attr)