do not skip span for newline textnodes otherwise compute_new_comment_positions() will return bad results for pandoc texts.
authorgibus
Wed, 27 Mar 2013 17:51:18 +0100
changeset 502 8ec189cc214d
parent 501 5cd02f32be5e
child 503 7ae7573ed7f1
child 504 b2e0186daa5b
do not skip span for newline textnodes otherwise compute_new_comment_positions() will return bad results for pandoc texts.
src/cm/utils/comment_positioning.py
src/cm/utils/spannifier.py
--- a/src/cm/utils/comment_positioning.py	Mon Mar 18 17:29:40 2013 +0100
+++ b/src/cm/utils/comment_positioning.py	Wed Mar 27 17:51:18 2013 +0100
@@ -16,8 +16,8 @@
     previousVersionContent = pandoc_convert(old_content, old_format, 'html')
     newVersionContent = pandoc_convert(new_content, new_format, 'html')
 
-    _, previous_char_list, span_starts_previous = spannify(previousVersionContent)
-    _, new_char_list, span_starts_new = spannify(newVersionContent)
+    _, previous_char_list, span_starts_previous = spannify(previousVersionContent, False)
+    _, new_char_list, span_starts_new = spannify(newVersionContent, False)
     
     sm = SequenceMatcher(None, previous_char_list, new_char_list)
     
--- a/src/cm/utils/spannifier.py	Mon Mar 18 17:29:40 2013 +0100
+++ b/src/cm/utils/spannifier.py	Wed Mar 27 17:51:18 2013 +0100
@@ -7,8 +7,8 @@
 def get_text_nodes(soup):
     return soup(text=lambda text:not isinstance(text, Comment))
 
-def is_real_text_node(textNode):
-    if textNode.string == "\n":
+def is_real_text_node(textNode, nolinefeed=True):
+    if nolinefeed and textNode.string == "\n":
       return False
     return not textNode.findParent('style') 
 
@@ -17,7 +17,7 @@
      
 from cm.utils.cache import memoize, dj_memoize
 @dj_memoize
-def spannify(input):
+def spannify(input, nolinefeed=True):
     """ 
     wrap textNodes in spans 
     """
@@ -32,7 +32,7 @@
     span_starts = {}
     for i in xrange(len(textNodes)):
         textNode = textNodes[i]
-        if is_real_text_node(textNode) :
+        if is_real_text_node(textNode, nolinefeed) :
             textNode.replaceWith('<span id="sv_' + str(i) + '" class="c-s"><span id="sv-' + str(i) + '" class="c-count-0 c-c">' + textNode.string + '</span></span>')
             span_starts[i] = len(''.join(textNodes_content))
             textNodes_content.append(textNode.string)