[CMF-checkins] CVS: CMF/CMFCollector - util.py:1.9

Ken Manheimer klm@zope.com
Wed, 31 Oct 2001 19:20:40 -0500


Update of /cvs-repository/CMF/CMFCollector
In directory cvs.zope.org:/tmp/cvs-serv1650

Modified Files:
	util.py 
Log Message:
Changes to tame the structured text problems, and remove the
processing for the emailled version of the transcript.  (I'm coming to
think it's a mistake to use ST for bug reports.  We need a *much*
smaller subset - text flow with blank-line broken paragraphs, and
preformatting for code.  Which could be *any* indented lines.)

process_comment(): Foremost, ditch the unnecessary indenting (which is
residue from the way i did commenting in WikiForNow, didn't think
through whether it applied here, sigh).

Also, qualify the <pre>/</pre> (with special attributes
"collector:deleteme", so they're still valid html, perhaps), for
stripping in the email messages.

unprocess_comment(): Invert the process_comment() treatment, for
sending the transcript as email.


=== CMF/CMFCollector/util.py 1.8 => 1.9 ===
     # Process the comment:
     # - Strip leading whitespace,
-    # - indent every line so it's contained as part of the prefix
-    #   definition list, and
     # - cause all cited text to be preformatted.
 
     inpre = incited = atcited = 0
@@ -162,7 +160,7 @@
     unpresplit = unpreexp.split
     citedsearch = citedexp.search
     got = []
-    for i in string.split(string.strip(comment), '\n') + ['']:
+    for i in string.split('\n' + string.rstrip(comment), '\n') + ['']:
         atcited = citedsearch(i)
         if not atcited:
             if incited:
@@ -170,7 +168,7 @@
                 incited = 0
                 if inpre:
                     # Close <pre> that we prepended.
-                    got.append(' </pre>')
+                    got.append("</pre collector:deleteme>")
                     inpre = 0
 
             # Check line for toggling of inpre.
@@ -195,10 +193,27 @@
             if not incited:
                 incited = 1
                 if not inpre:
-                    got.append(' <pre>')
+                    got.append("<pre collector:deleteme>")
                     inpre = 1
-        got.append(' ' + i)
+        got.append(i)
     return string.strip(string.join(got, '\n'))
+
+
+def unprocess_comments(text):
+    """Invert the process_comment transformations to yield literal text.
+
+    Specifically, remove (special) <pre>/</pre> and turn the small set of
+    character entities back to characters."""
+    
+    if text.find("<pre collector:deleteme>\n"):
+        text = text.replace("<pre collector:deleteme>\n", '')
+    if text.find("</pre collector:deleteme>\n"):
+        text = text.replace("</pre collector:deleteme>\n", '')
+    if text.find('&amp;'):
+        text = text.replace('&amp;', '&')
+    if text.find('&lt;'):
+        text = text.replace('&lt;', '<')
+    return text
 
 def sorted(l):
     x = list(l[:])