[Zope-Checkins] CVS: Zope2 - ST.py:1.11
chrism@serenade.digicool.com
chrism@serenade.digicool.com
Tue, 12 Jun 2001 16:59:26 -0400
Update of /cvs-repository/Zope2/lib/python/StructuredText
In directory serenade:/home/chrism/sandboxes/NewProduct/lib/python/StructuredText
Modified Files:
ST.py
Log Message:
When operating on raw strings which had DOS-style linefeeds (e.g. "\r\n"), StructuredText would neglect to strip the trailing garbage off the end of a paragraph. Thus, the test for "examples" and other features that depended on the last characters in a paragraph to not be whitespace for proper operation were failing, causing problems mainly for people who use Windows to author STX content. This is now fixed.
--- Updated File ST.py in package Zope2 --
--- ST.py 2001/05/14 18:38:27 1.10
+++ ST.py 2001/06/12 20:59:26 1.11
@@ -90,10 +90,12 @@
highest = key
return highest-1
+para_delim = r'(\n\s*\n|\r\n\s*\r\n)' # UNIX or DOS line endings, respectively
+
#####################################################################
# Golly, the capitalization of this function always makes me think it's a class
-def StructuredText(paragraphs, paragraph_delimiter=re.compile('\n\s*\n')):
+def StructuredText(paragraphs, delimiter=re.compile(para_delim)):
"""
StructuredText accepts paragraphs, which is a list of
lines to be parsed. StructuredText creates a structure
@@ -107,12 +109,12 @@
level = 0 # which header are we under
struct = [] # the structure to be returned
run = struct
-
- paragraphs = filter(
- strip,
- paragraph_delimiter.split(expandtabs('\n\n'+paragraphs+'\n\n'))
- )
-
+
+ paragraphs = expandtabs(paragraphs)
+ paragraphs = '%s%s%s' % ('\n\n', paragraphs, '\n\n')
+ paragraphs = delimiter.split(paragraphs)
+ paragraphs = filter(strip, paragraphs)
+
if not paragraphs: return StructuredTextDocument()
ind = [] # structure based on indention levels