Update of /cvsroot/happydoc/HappyDoc/happydoclib/docstring/StructuredText
In directory usw-pr-cvs1:/tmp/cvs-serv474/happydoclib/docstring/StructuredText
Modified Files:
ClassicDocumentClass.py ClassicStructuredText.py
DocBookClass.py DocumentClass.py DocumentWithImages.py
HTMLClass.py HTMLWithImages.py ST.py STDOM.py STletters.py
StructuredText.py Zwiki.py __init__.py
Log Message:
Updated to the latest StructuredText implementation from Zope CVS.
Index: ClassicDocumentClass.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/docstring/StructuredText/ClassicDocumentClass.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ClassicDocumentClass.py 8 Dec 2001 15:33:27 -0000 1.2
--- ClassicDocumentClass.py 25 Aug 2002 14:40:59 -0000 1.3
***************
*** 2,6 ****
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
--- 2,6 ----
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
[...988 lines suppressed...]
-
-
-
-
-
-
--- 608,620 ----
end = end -1
link = s[st:end]
! #end = end - 1
!
# name is the href title, link is the target
# of the href
return (StructuredTextLink(name, href=link),
start, end)
!
#return (StructuredTextLink(s[start:end], href=s[start:end]),
# start, end)
else:
return None
Index: ClassicStructuredText.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/docstring/StructuredText/ClassicStructuredText.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ClassicStructuredText.py 8 Dec 2001 15:33:27 -0000 1.2
--- ClassicStructuredText.py 25 Aug 2002 14:40:59 -0000 1.3
***************
*** 1,10 ****
#! /usr/bin/env python -- # -*- python -*-
- #
- # HappyDoc:docStringFormat='ClassicStructuredText'
- #
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
--- 1,7 ----
#! /usr/bin/env python -- # -*- python -*-
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
***************
*** 13,25 ****
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
! #
##############################################################################
'''Structured Text Manipulation
! Parse a structured text string into a form that can be used with
structured formats, like html.
Structured text is text that uses indentation and simple
! symbology to indicate the structure of a document.
A structured string consists of a sequence of paragraphs separated by
--- 10,22 ----
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
! #
##############################################################################
'''Structured Text Manipulation
! Parse a structured text string into a form that can be used with
structured formats, like html.
Structured text is text that uses indentation and simple
! symbology to indicate the structure of a document.
A structured string consists of a sequence of paragraphs separated by
***************
*** 64,68 ****
is made strong.
! - Text surrounded by '_' underscore characters (with whitespace to the left
and whitespace or punctuation to the right) is made underlined.
--- 61,65 ----
is made strong.
! - Text surrounded by '_' underscore characters (with whitespace to the left
and whitespace or punctuation to the right) is made underlined.
***************
*** 78,91 ****
- Text enclosed by double quotes followed by a comma, one or more spaces,
an absolute URL and concluded by punctuation plus white space, or just
! white space, is treated as a hyper link. For example:
"mail me", mailto:am...@di....
! Is interpreted as '<a href="mailto:am...@di...">mail me</a>.'
- Text enclosed in brackets which consists only of letters, digits,
underscores and dashes is treated as hyper links within the document.
For example:
!
As demonstrated by Smith [12] this technique is quite effective.
--- 75,88 ----
- Text enclosed by double quotes followed by a comma, one or more spaces,
an absolute URL and concluded by punctuation plus white space, or just
! white space, is treated as a hyper link. For example:
"mail me", mailto:am...@di....
! Is interpreted as '<a href="mailto:am...@di...">mail me</a>.'
- Text enclosed in brackets which consists only of letters, digits,
underscores and dashes is treated as hyper links within the document.
For example:
!
As demonstrated by Smith [12] this technique is quite effective.
***************
*** 96,104 ****
periods and a space is treated as a named link. For example:
! .. [12] "Effective Techniques" Smith, Joe ...
Is interpreted as '<a name="12">[12]</a> "Effective Techniques" ...'.
Together with the previous rule this allows easy coding of references or
! end notes.
--- 93,101 ----
periods and a space is treated as a named link. For example:
! .. [12] "Effective Techniques" Smith, Joe ...
Is interpreted as '<a name="12">[12]</a> "Effective Techniques" ...'.
Together with the previous rule this allows easy coding of references or
! end notes.
***************
*** 140,144 ****
import regex
from ts_regex import gsub
- from string import split, join, strip, find
import string,re
--- 137,140 ----
***************
*** 166,174 ****
def indent(aString, indent=2):
"""Indent a string the given number of spaces"""
! r=split(untabify(aString),'\n')
if not r: return ''
if not r[-1]: del r[-1]
! tab=' '*level
! return "%s%s\n" % (tab,join(r,'\n'+tab))
def reindent(aString, indent=2, already_untabified=0):
--- 162,170 ----
def indent(aString, indent=2):
"""Indent a string the given number of spaces"""
! r=untabify(aString).split('\n')
if not r: return ''
if not r[-1]: del r[-1]
! tab=' '*indent
! return "%s%s\n" % (tab,('\n'+tab).join(r))
def reindent(aString, indent=2, already_untabified=0):
***************
*** 186,195 ****
if indent > l:
tab=' ' * (indent-l)
! for s in split(aString,'\n'): append(tab+s)
else:
l=l-indent
! for s in split(aString,'\n'): append(s[l:])
! return join(r,'\n')
def indent_level(aString,
--- 182,191 ----
if indent > l:
tab=' ' * (indent-l)
! for s in aString.split('\n'): append(tab+s)
else:
l=l-indent
! for s in aString.split('\n'): append(s[l:])
! return '\n'.join(r)
def indent_level(aString,
***************
*** 239,254 ****
ROW=' <TR>\n%s </TR>\n'
TABLE='\n<TABLE BORDER=1 CELLPADDING=2>\n%s</TABLE>'
-
def create(self,aPar,
! #
! # HappyDoc fix
! #
! # td_reg=re.compile(r'[ \t\n]*\|\|([^\0x00|]*)')
! td_reg=re.compile(r'[ \t\n]*\|\|([^|]*)')
):
'''parses a table and returns nested list representing the
table'''
self.table=[]
! text=filter(None,split(aPar,'\n'))
for line in text:
row=[]
--- 235,245 ----
ROW=' <TR>\n%s </TR>\n'
TABLE='\n<TABLE BORDER=1 CELLPADDING=2>\n%s</TABLE>'
def create(self,aPar,
! td_reg=re.compile(r'[ \t\n]*\|\|([^\0|]*)')
):
'''parses a table and returns nested list representing the
table'''
self.table=[]
! text=filter(None,aPar.split('\n'))
for line in text:
row=[]
***************
*** 276,281 ****
htmlrow.append(self.CELL%(colspan,cell))
colspan=1
! htmltable.append(self.ROW%join(htmlrow,''))
! return self.TABLE%join(htmltable,'')
table=Table()
--- 267,272 ----
htmlrow.append(self.CELL%(colspan,cell))
colspan=1
! htmltable.append(self.ROW % ''.join(htmlrow))
! return self.TABLE % ''.join(htmltable)
table=Table()
***************
*** 305,317 ****
pat = ' \"([%s0-9-_,./?=@~&]*)\":' % string.letters+ \
'([-:%s0-9_,./?=@#~&]*?)' % string.letters + \
! '([.:?;] )'
p_reg = re.compile(pat,re.M)
!
aStructuredString = p_reg.sub(r'<a href="\2">\1</a>\3 ' , aStructuredString)
pat = ' \"([%s0-9-_,./?=@~&]*)\", ' % string.letters+ \
'([-:%s0-9_,./?=@#~&]*?)' % string.letters + \
! '([.:?;] )'
p_reg = re.compile(pat,re.M)
--- 296,308 ----
pat = ' \"([%s0-9-_,./?=@~&]*)\":' % string.letters+ \
'([-:%s0-9_,./?=@#~&]*?)' % string.letters + \
! '([.:?;] )'
p_reg = re.compile(pat,re.M)
!
aStructuredString = p_reg.sub(r'<a href="\2">\1</a>\3 ' , aStructuredString)
pat = ' \"([%s0-9-_,./?=@~&]*)\", ' % string.letters+ \
'([-:%s0-9_,./?=@#~&]*?)' % string.letters + \
! '([.:?;] )'
p_reg = re.compile(pat,re.M)
***************
*** 320,324 ****
! protoless = find(aStructuredString, '<a href=":')
if protoless != -1:
aStructuredString = re.sub('<a href=":', '<a href="',
--- 311,315 ----
! protoless = aStructuredString.find('<a href=":')
if protoless != -1:
aStructuredString = re.sub('<a href=":', '<a href="',
***************
*** 337,344 ****
! ctag_prefix=r'([\x00- \\(]|^)'
! ctag_suffix=r'([\x00- ,.:;!?\\)]|$)'
! ctag_middle=r'[%s]([^\x00- %s][^%s]*[^\x00- %s]|[^%s])[%s]'
! ctag_middl2=r'[%s][%s]([^\x00- %s][^%s]*[^\x00- %s]|[^%s])[%s][%s]'
def ctag(s,
--- 328,335 ----
! ctag_prefix=r'([\x00- \\(]|^)'
! ctag_suffix=r'([\x00- ,.:;!?\\)]|$)'
! ctag_middle=r'[%s]([^\x00- %s][^%s]*[^\x00- %s]|[^%s])[%s]'
! ctag_middl2=r'[%s][%s]([^\x00- %s][^%s]*[^\x00- %s]|[^%s])[%s][%s]'
def ctag(s,
***************
*** 357,361 ****
s=code.sub( r'\1<code>\2</code>\3',s)
s=em.sub( r'\1<em>\2</em>\3',s)
! return s
class HTML(StructuredText):
--- 348,352 ----
s=code.sub( r'\1<code>\2</code>\3',s)
s=em.sub( r'\1<em>\2</em>\3',s)
! return s
class HTML(StructuredText):
***************
*** 381,390 ****
def ul(self, before, p, after):
! if p: p="<p>%s</p>" % strip(ctag(p))
return ('%s<ul><li>%s\n%s\n</li></ul>\n'
% (before,p,after))
def ol(self, before, p, after):
! if p: p="<p>%s</p>" % strip(ctag(p))
return ('%s<ol><li>%s\n%s\n</li></ol>\n'
% (before,p,after))
--- 372,381 ----
def ul(self, before, p, after):
! if p: p="<p>%s</p>" % ctag(p).strip()
return ('%s<ul><li>%s\n%s\n</li></ul>\n'
% (before,p,after))
def ol(self, before, p, after):
! if p: p="<p>%s</p>" % ctag(p).strip()
return ('%s<ol><li>%s\n%s\n</li></ol>\n'
% (before,p,after))
***************
*** 397,403 ****
if level > 0 and level < 6:
return ('%s<h%d>%s</h%d>\n%s\n'
! % (before,level,strip(ctag(t)),level,d))
!
! t="<p><strong>%s</strong></p>" % strip(ctag(t))
return ('%s<dl><dt>%s\n</dt><dd>%s\n</dd></dl>\n'
% (before,t,d))
--- 388,394 ----
if level > 0 and level < 6:
return ('%s<h%d>%s</h%d>\n%s\n'
! % (before,level,ctag(t).strip(),level,d))
!
! t="<p><strong>%s</strong></p>" % ctag(t).strip()
return ('%s<dl><dt>%s\n</dt><dd>%s\n</dd></dl>\n'
% (before,t,d))
***************
*** 416,423 ****
if not tagged: r=r+'</PRE>\n'
return r
!
def table(self,before,table,after):
return '%s<p>%s</p>\n%s\n' % (before,ctag(table),after)
!
def _str(self,structure,level,
# Static
--- 407,414 ----
if not tagged: r=r+'</PRE>\n'
return r
!
def table(self,before,table,after):
return '%s<p>%s</p>\n%s\n' % (before,ctag(table),after)
!
def _str(self,structure,level,
# Static
***************
*** 486,490 ****
r=self.normal(r,s[0],self._str(s[1],level))
return r
!
def html_quote(v,
--- 477,481 ----
r=self.normal(r,s[0],self._str(s[1],level))
return r
!
def html_quote(v,
***************
*** 495,502 ****
(re.compile('"'), '"')
)): #"
! text=str(v)
! for re,name in character_entities:
! text=re.sub(name,text)
! return text
def html_with_references(text, level=1):
--- 486,493 ----
(re.compile('"'), '"')
)): #"
! text=str(v)
! for re,name in character_entities:
! text=re.sub(name,text)
! return text
def html_with_references(text, level=1):
***************
*** 510,514 ****
r'\1<a href="#\2">[\2]</a>\3',
text)
!
text = re.sub(
r'([\0- ,])\[([^]]+)\.html\]([\0- ,.:])',
--- 501,505 ----
r'\1<a href="#\2">[\2]</a>\3',
text)
!
text = re.sub(
r'([\0- ,])\[([^]]+)\.html\]([\0- ,.:])',
***************
*** 517,521 ****
return HTML(text,level=level)
!
def main():
--- 508,512 ----
return HTML(text,level=level)
!
def main():
***************
*** 545,552 ****
if mo is not None:
s = s[len(mo.group(0)) :]
!
s=str(html_with_references(s))
if s[:4]=='<h1>':
! t=s[4:find(s,'</h1>')]
s='''<html><head><title>%s</title>
</head><body>
--- 536,543 ----
if mo is not None:
s = s[len(mo.group(0)) :]
!
s=str(html_with_references(s))
if s[:4]=='<h1>':
! t=s[4: s.find('</h1>')]
s='''<html><head><title>%s</title>
</head><body>
Index: DocBookClass.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/docstring/StructuredText/DocBookClass.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DocBookClass.py 8 Dec 2001 13:55:19 -0000 1.2
--- DocBookClass.py 25 Aug 2002 14:40:59 -0000 1.3
***************
*** 2,6 ****
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
--- 2,6 ----
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
***************
*** 9,212 ****
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
! #
##############################################################################
- import string
- from string import join, split, find, lstrip
class DocBookClass:
! element_types={
! '#text': '_text',
! 'StructuredTextDocument': 'document',
! 'StructuredTextParagraph': 'paragraph',
! 'StructuredTextExample': 'example',
! 'StructuredTextBullet': 'bullet',
! 'StructuredTextNumbered': 'numbered',
! 'StructuredTextDescription': 'description',
! 'StructuredTextDescriptionTitle': 'descriptionTitle',
! 'StructuredTextDescriptionBody': 'descriptionBody',
! 'StructuredTextSection': 'section',
! 'StructuredTextSectionTitle': 'sectionTitle',
! 'StructuredTextLiteral': 'literal',
! 'StructuredTextEmphasis': 'emphasis',
! 'StructuredTextStrong': 'strong',
! 'StructuredTextLink': 'link',
! 'StructuredTextXref': 'xref',
! 'StructuredTextSGML': 'sgml',
! }
! def dispatch(self, doc, level, output):
! getattr(self, self.element_types[doc.getNodeName()])(doc, level, output)
!
! def __call__(self, doc, level=1):
! r=[]
! self.dispatch(doc, level-1, r.append)
! return join(r,'')
! def _text(self, doc, level, output):
! if doc.getNodeName() == 'StructuredTextLiteral':
! output(doc.getNodeValue())
! else:
! output(lstrip(doc.getNodeValue()))
! def document(self, doc, level, output):
! output('<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN">\n')
! output('<book>\n')
! children=doc.getChildNodes()
! if (children and
! children[0].getNodeName() == 'StructuredTextSection'):
! output('<title>%s</title>' % children[0].getChildNodes()[0].getNodeValue())
! for c in children:
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</book>\n')
! def section(self, doc, level, output):
! output('\n<section>\n')
! children=doc.getChildNodes()
! for c in children:
! getattr(self, self.element_types[c.getNodeName()])(c, level+1, output)
! output('\n</section>\n')
!
! def sectionTitle(self, doc, level, output):
! output('<title>')
! for c in doc.getChildNodes():
! try:
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! except:
! print "failed", c.getNodeName(), c
! output('</title>\n')
! def description(self, doc, level, output):
! p=doc.getPreviousSibling()
! if p is None or p.getNodeName() is not doc.getNodeName():
! output('<variablelist>\n')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! n=doc.getNextSibling()
! if n is None or n.getNodeName() is not doc.getNodeName():
! output('</variablelist>\n')
!
! def descriptionTitle(self, doc, level, output):
! output('<varlistentry><term>\n')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</term>\n')
!
! def descriptionBody(self, doc, level, output):
! output('<listitem><para>\n')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</para></listitem>\n')
! output('</varlistentry>\n')
! def bullet(self, doc, level, output):
! p=doc.getPreviousSibling()
! if p is None or p.getNodeName() is not doc.getNodeName():
! output('<itemizedlist>\n')
! output('<listitem><para>\n')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! n=doc.getNextSibling()
! output('</para></listitem>\n')
! if n is None or n.getNodeName() is not doc.getNodeName():
! output('</itemizedlist>\n')
! def numbered(self, doc, level, output):
! p=doc.getPreviousSibling()
! if p is None or p.getNodeName() is not doc.getNodeName():
! output('<orderedlist>\n')
! output('<listitem><para>\n')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! n=doc.getNextSibling()
! output('</para></listitem>\n')
! if n is None or n.getNodeName() is not doc.getNodeName():
! output('</orderedlist>\n')
! def example(self, doc, level, output):
! i=0
! for c in doc.getChildNodes():
! if i==0:
! output('<programlisting>\n<![CDATA[\n')
! ##
! ## eek. A ']]>' in your body will break this...
! ##
! output(prestrip(c.getNodeValue()))
! output('\n]]></programlisting>\n')
! else:
getattr(self, self.element_types[c.getNodeName()])(
c, level, output)
! def paragraph(self, doc, level, output):
! output('<para>\n\n')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(
! c, level, output)
! output('</para>\n\n')
!
! def link(self, doc, level, output):
! output('<ulink url="%s">' % doc.href)
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</ulink>')
! def emphasis(self, doc, level, output):
! output('<emphasis>')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</emphasis> ')
! def literal(self, doc, level, output):
! output('<literal>')
! for c in doc.getChildNodes():
! output(c.getNodeValue())
! output('</literal>')
! def strong(self, doc, level, output):
! output('<emphasis>')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</emphasis>')
! def xref(self, doc, level, output):
! output('<xref linkend="%s"/>' % doc.getNodeValue())
! def sgml(self, doc, level, output):
! output(doc.getNodeValue())
def prestrip(v):
! v=string.replace(v, '\r\n', '\n')
! v=string.replace(v, '\r', '\n')
! v=string.replace(v, '\t', ' ')
! lines=string.split(v, '\n')
! indent=len(lines[0])
! for line in lines:
! if not len(line): continue
! i=len(line)-len(string.lstrip(line))
! if i < indent:
! indent=i
! nlines=[]
! for line in lines:
! nlines.append(line[indent:])
! return string.join(nlines, '\n')
class DocBookChapter(DocBookClass):
! def document(self, doc, level, output):
! output('<chapter>\n')
! children=doc.getChildNodes()
! if (children and
! children[0].getNodeName() == 'StructuredTextSection'):
! output('<title>%s</title>' % children[0].getChildNodes()[0].getNodeValue())
! for c in children[0].getChildNodes()[1:]:
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</chapter>\n')
ets = DocBookClass.element_types
! ets.update({'StructuredTextImage': 'image'})
class DocBookChapterWithFigures(DocBookChapter):
--- 9,210 ----
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
! #
##############################################################################
class DocBookClass:
! element_types={
! '#text': '_text',
! 'StructuredTextDocument': 'document',
! 'StructuredTextParagraph': 'paragraph',
! 'StructuredTextExample': 'example',
! 'StructuredTextBullet': 'bullet',
! 'StructuredTextNumbered': 'numbered',
! 'StructuredTextDescription': 'description',
! 'StructuredTextDescriptionTitle': 'descriptionTitle',
! 'StructuredTextDescriptionBody': 'descriptionBody',
! 'StructuredTextSection': 'section',
! 'StructuredTextSectionTitle': 'sectionTitle',
! 'StructuredTextLiteral': 'literal',
! 'StructuredTextEmphasis': 'emphasis',
! 'StructuredTextStrong': 'strong',
! 'StructuredTextLink': 'link',
! 'StructuredTextXref': 'xref',
! 'StructuredTextSGML': 'sgml',
! }
! def dispatch(self, doc, level, output):
! getattr(self, self.element_types[doc.getNodeName()])(doc, level, output)
! def __call__(self, doc, level=1):
! r=[]
! self.dispatch(doc, level-1, r.append)
! return ''.join(r)
! def _text(self, doc, level, output):
! if doc.getNodeName() == 'StructuredTextLiteral':
! output(doc.getNodeValue())
! else:
! output(doc.getNodeValue().lstrip())
! def document(self, doc, level, output):
! output('<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN">\n')
! output('<book>\n')
! children=doc.getChildNodes()
! if (children and
! children[0].getNodeName() == 'StructuredTextSection'):
! output('<title>%s</title>' % children[0].getChildNodes()[0].getNodeValue())
! for c in children:
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</book>\n')
! def section(self, doc, level, output):
! output('\n<section>\n')
! children=doc.getChildNodes()
! for c in children:
! getattr(self, self.element_types[c.getNodeName()])(c, level+1, output)
! output('\n</section>\n')
! def sectionTitle(self, doc, level, output):
! output('<title>')
! for c in doc.getChildNodes():
! try:
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! except:
! print "failed", c.getNodeName(), c
! output('</title>\n')
! def description(self, doc, level, output):
! p=doc.getPreviousSibling()
! if p is None or p.getNodeName() is not doc.getNodeName():
! output('<variablelist>\n')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! n=doc.getNextSibling()
! if n is None or n.getNodeName() is not doc.getNodeName():
! output('</variablelist>\n')
! def descriptionTitle(self, doc, level, output):
! output('<varlistentry><term>\n')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</term>\n')
! def descriptionBody(self, doc, level, output):
! output('<listitem><para>\n')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</para></listitem>\n')
! output('</varlistentry>\n')
!
! def bullet(self, doc, level, output):
! p=doc.getPreviousSibling()
! if p is None or p.getNodeName() is not doc.getNodeName():
! output('<itemizedlist>\n')
! output('<listitem><para>\n')
!
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! n=doc.getNextSibling()
! output('</para></listitem>\n')
! if n is None or n.getNodeName() is not doc.getNodeName():
! output('</itemizedlist>\n')
!
! def numbered(self, doc, level, output):
! p=doc.getPreviousSibling()
! if p is None or p.getNodeName() is not doc.getNodeName():
! output('<orderedlist>\n')
! output('<listitem><para>\n')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! n=doc.getNextSibling()
! output('</para></listitem>\n')
! if n is None or n.getNodeName() is not doc.getNodeName():
! output('</orderedlist>\n')
!
! def example(self, doc, level, output):
! i=0
! for c in doc.getChildNodes():
! if i==0:
! output('<programlisting>\n<![CDATA[\n')
! ##
! ## eek. A ']]>' in your body will break this...
! ##
! output(prestrip(c.getNodeValue()))
! output('\n]]></programlisting>\n')
! else:
! getattr(self, self.element_types[c.getNodeName()])(
! c, level, output)
!
! def paragraph(self, doc, level, output):
! output('<para>\n\n')
! for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(
c, level, output)
+ output('</para>\n\n')
! def link(self, doc, level, output):
! output('<ulink url="%s">' % doc.href)
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</ulink>')
! def emphasis(self, doc, level, output):
! output('<emphasis>')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</emphasis> ')
! def literal(self, doc, level, output):
! output('<literal>')
! for c in doc.getChildNodes():
! output(c.getNodeValue())
! output('</literal>')
! def strong(self, doc, level, output):
! output('<emphasis>')
! for c in doc.getChildNodes():
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</emphasis>')
! def xref(self, doc, level, output):
! output('<xref linkend="%s"/>' % doc.getNodeValue())
! def sgml(self, doc, level, output):
! output(doc.getNodeValue())
def prestrip(v):
! v=v.replace( '\r\n', '\n')
! v=v.replace( '\r', '\n')
! v=v.replace( '\t', ' ')
! lines=v.split('\n')
! indent=len(lines[0])
! for line in lines:
! if not len(line): continue
! i=len(line)-len(line.lstrip())
! if i < indent:
! indent=i
! nlines=[]
! for line in lines:
! nlines.append(line[indent:])
! return '\n'.join(nlines, '\n')
class DocBookChapter(DocBookClass):
! def document(self, doc, level, output):
! output('<chapter>\n')
! children=doc.getChildNodes()
! if (children and
! children[0].getNodeName() == 'StructuredTextSection'):
! output('<title>%s</title>' % children[0].getChildNodes()[0].getNodeValue())
! for c in children[0].getChildNodes()[1:]:
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</chapter>\n')
ets = DocBookClass.element_types
! ets.update({'StructuredTextImage': 'image'})
class DocBookChapterWithFigures(DocBookChapter):
***************
*** 215,260 ****
def image(self, doc, level, output):
! if hasattr(doc, 'key'):
! output('<figure id="%s"><title>%s</title>\n' % (doc.key, doc.getNodeValue()) )
! else:
! output('<figure><title>%s</title>\n' % doc.getNodeValue())
## for c in doc.getChildNodes():
## getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('<graphic fileref="%s"></graphic>\n</figure>\n' % doc.href)
class DocBookArticle(DocBookClass):
! def document(self, doc, level, output):
! output('<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V4.1//EN">\n')
! output('<article>\n')
! children=doc.getChildNodes()
! if (children and
! children[0].getNodeName() == 'StructuredTextSection'):
! output('<articleinfo>\n<title>%s</title>\n</articleinfo>\n' %
! children[0].getChildNodes()[0].getNodeValue())
! for c in children:
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</article>\n')
class DocBookBook:
! def __init__(self, title=''):
! self.title = title
! self.chapters = []
!
! def addChapter(self, chapter):
! self.chapters.append(chapter)
! def read(self):
! out = '<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN">\n<book>\n'
! out = out + '<title>%s</title>\n' % self.title
! for chapter in self.chapters:
! out = out + chapter + '\n</book>\n'
! return out
! def __str__(self):
! return self.read()
!
--- 213,256 ----
def image(self, doc, level, output):
! if hasattr(doc, 'key'):
! output('<figure id="%s"><title>%s</title>\n' % (doc.key, doc.getNodeValue()) )
! else:
! output('<figure><title>%s</title>\n' % doc.getNodeValue())
## for c in doc.getChildNodes():
## getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('<graphic fileref="%s"></graphic>\n</figure>\n' % doc.href)
class DocBookArticle(DocBookClass):
! def document(self, doc, level, output):
! output('<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V4.1//EN">\n')
! output('<article>\n')
! children=doc.getChildNodes()
! if (children and
! children[0].getNodeName() == 'StructuredTextSection'):
! output('<articleinfo>\n<title>%s</title>\n</articleinfo>\n' %
! children[0].getChildNodes()[0].getNodeValue())
! for c in children:
! getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! output('</article>\n')
class DocBookBook:
! def __init__(self, title=''):
! self.title = title
! self.chapters = []
! def addChapter(self, chapter):
! self.chapters.append(chapter)
! def read(self):
! out = '<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN">\n<book>\n'
! out = out + '<title>%s</title>\n' % self.title
! for chapter in self.chapters:
! out = out + chapter + '\n</book>\n'
! return out
+ def __str__(self):
+ return self.read()
Index: DocumentClass.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/docstring/StructuredText/DocumentClass.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DocumentClass.py 8 Dec 2001 15:33:27 -0000 1.2
--- DocumentClass.py 25 Aug 2002 14:40:59 -0000 1.3
***************
*** 2,6 ****
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
--- 2,6 ----
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
[...1400 lines suppressed...]
# of the href
return (StructuredTextLink(name, href=link),
start, end)
!
#return (StructuredTextLink(s[start:end], href=s[start:end]),
# start, end)
else:
return None
!
def doc_sgml(self,s,expr=re.compile(r"\<[%s0-9\.\=\'\"\:\/\-\#\+\s\*]+\>" % letters).search):
"""
***************
*** 948,953 ****
else:
return None
-
-
-
-
--- 952,953 ----
Index: DocumentWithImages.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/docstring/StructuredText/DocumentWithImages.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DocumentWithImages.py 8 Dec 2001 13:55:42 -0000 1.2
--- DocumentWithImages.py 25 Aug 2002 14:40:59 -0000 1.3
***************
*** 2,6 ****
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
--- 2,6 ----
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
***************
*** 9,18 ****
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
! #
##############################################################################
! import re, ST, STDOM
! from string import split, join, replace, expandtabs, strip, find
!
from DocumentClass import *
--- 9,16 ----
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
! #
##############################################################################
! import re
from DocumentClass import *
***************
*** 20,24 ****
"A simple embedded image"
! class DocumentWithImages(DocumentClass):
"""
--- 18,22 ----
"A simple embedded image"
! class DocumentWithImages(DocumentClass):
"""
***************
*** 33,38 ****
def doc_img(
self, s,
! expr1=re.compile('\"([ _a-zA-Z0-9*.:/;,\-\n\~]+)\":img:([a-zA-Z0-9\-.:/;,\n\~]+)').search,
! expr2=re.compile('\"([ _a-zA-Z0-9*.:/;,\-\n\~]+)\":img:([a-zA-Z0-9\-.:/;,\n\~]+):([a-zA-Z0-9\-.:/;,\n\~]+)').search
):
--- 31,36 ----
def doc_img(
self, s,
! expr1=re.compile('\"([ _a-zA-Z0-9*.:/;,\-\n\~]+)\":img:([a-zA-Z0-9\_\-.:/;,\n\~]+)').search,
! expr2=re.compile('\"([ _a-zA-Z0-9*.:/;,\-\n\~]+)\":img:([a-zA-Z0-9\_\-.:/;,\n\~]+):([a-zA-Z0-9_\-.:/;,\n\~]+)').search
):
***************
*** 47,61 ****
if not r.group(2) in ['http','file','ftp']:
! startt, endt = r.span(1)
! startk, endk = r.span(2)
! starth, endh = r.span(3)
! start, end = r.span()
!
! key = s[startk:endk]
!
! return (StructuredTextImage(s[startt:endt], href=s[starth:endh], key=s[startk:endk]),
! start, end)
-
r=expr1(s)
if r:
--- 45,59 ----
if not r.group(2) in ['http','file','ftp']:
! startt, endt = r.span(1)
! startk, endk = r.span(2)
! starth, endh = r.span(3)
! start, end = r.span()
!
! key = s[startk:endk]
!
! return (StructuredTextImage(s[startt:endt], href=s[starth:endh], key=s[startk:endk]),
! start, end)
!
r=expr1(s)
if r:
***************
*** 67,69 ****
return None
-
--- 65,66 ----
Index: HTMLClass.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/docstring/StructuredText/HTMLClass.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HTMLClass.py 8 Dec 2001 15:33:27 -0000 1.2
--- HTMLClass.py 25 Aug 2002 14:40:59 -0000 1.3
***************
*** 2,6 ****
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
--- 2,6 ----
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
***************
*** 9,16 ****
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
! #
##############################################################################
- from string import join, split, find
from cgi import escape
import re, sys, ST
--- 9,15 ----
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
! #
##############################################################################
from cgi import escape
import re, sys, ST
***************
*** 45,62 ****
def dispatch(self, doc, level, output):
getattr(self, self.element_types[doc.getNodeName()])(doc, level, output)
!
def __call__(self, doc, level=1, header=1):
r=[]
self.header = header
self.dispatch(doc, level-1, r.append)
! return join(r,'')
def _text(self, doc, level, output):
! output((doc.getNodeValue()))
def document(self, doc, level, output):
children=doc.getChildNodes()
! if self.header==1:
output('<html>\n')
if (children and
--- 44,61 ----
def dispatch(self, doc, level, output):
getattr(self, self.element_types[doc.getNodeName()])(doc, level, output)
!
def __call__(self, doc, level=1, header=1):
r=[]
self.header = header
self.dispatch(doc, level-1, r.append)
! return ''.join(r)
def _text(self, doc, level, output):
! output(doc.getNodeValue())
def document(self, doc, level, output):
children=doc.getChildNodes()
! if self.header:
output('<html>\n')
if (children and
***************
*** 69,73 ****
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! if self.header==1:
output('</body>\n')
output('</html>\n')
--- 68,72 ----
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
! if self.header:
output('</body>\n')
output('</html>\n')
***************
*** 77,81 ****
for c in children:
getattr(self, self.element_types[c.getNodeName()])(c, level+1, output)
!
def sectionTitle(self, doc, level, output):
output('<h%d>' % (level))
--- 76,80 ----
for c in children:
getattr(self, self.element_types[c.getNodeName()])(c, level+1, output)
!
def sectionTitle(self, doc, level, output):
output('<h%d>' % (level))
***************
*** 86,97 ****
def description(self, doc, level, output):
p=doc.getPreviousSibling()
! if p is None or p.getNodeName() is not doc.getNodeName():
output('<dl>\n')
for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
n=doc.getNextSibling()
! if n is None or n.getNodeName() is not doc.getNodeName():
output('</dl>\n')
!
def descriptionTitle(self, doc, level, output):
output('<dt>')
--- 85,96 ----
def description(self, doc, level, output):
p=doc.getPreviousSibling()
! if p is None or p.getNodeName() is not doc.getNodeName():
output('<dl>\n')
for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
n=doc.getNextSibling()
! if n is None or n.getNodeName() is not doc.getNodeName():
output('</dl>\n')
!
def descriptionTitle(self, doc, level, output):
output('<dt>')
***************
*** 99,103 ****
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
output('</dt>\n')
!
def descriptionBody(self, doc, level, output):
output('<dd>')
--- 98,102 ----
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
output('</dt>\n')
!
def descriptionBody(self, doc, level, output):
output('<dd>')
***************
*** 110,130 ****
if p is None or p.getNodeName() is not doc.getNodeName():
output('\n<ul>\n')
! output('<li><p>')
for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
n=doc.getNextSibling()
! output('</p></li>\n')
! if n is None or n.getNodeName() is not doc.getNodeName():
output('\n</ul>\n')
def numbered(self, doc, level, output):
p=doc.getPreviousSibling()
! if p is None or p.getNodeName() is not doc.getNodeName():
output('\n<ol>\n')
! output('<li><p>')
for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
n=doc.getNextSibling()
! output('</p></li>\n')
if n is None or n.getNodeName() is not doc.getNodeName():
output('\n</ol>\n')
--- 109,129 ----
if p is None or p.getNodeName() is not doc.getNodeName():
output('\n<ul>\n')
! output('<li>')
for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
n=doc.getNextSibling()
! output('</li>\n')
! if n is None or n.getNodeName() is not doc.getNodeName():
output('\n</ul>\n')
def numbered(self, doc, level, output):
p=doc.getPreviousSibling()
! if p is None or p.getNodeName() is not doc.getNodeName():
output('\n<ol>\n')
! output('<li>')
for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
n=doc.getNextSibling()
! output('</li>\n')
if n is None or n.getNodeName() is not doc.getNodeName():
output('\n</ol>\n')
***************
*** 142,146 ****
def paragraph(self, doc, level, output):
! i=0
output('<p>')
for c in doc.getChildNodes():
--- 141,145 ----
def paragraph(self, doc, level, output):
!
output('<p>')
for c in doc.getChildNodes():
***************
*** 176,180 ****
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
output('</strong>')
!
def underline(self, doc, level, output):
output("<u>")
--- 175,179 ----
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
output('</strong>')
!
def underline(self, doc, level, output):
output("<u>")
***************
*** 182,186 ****
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
output("</u>")
!
def innerLink(self, doc, level, output):
output('<a href="#ref');
--- 181,185 ----
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
output("</u>")
!
def innerLink(self, doc, level, output):
output('<a href="#ref');
***************
*** 191,195 ****
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
output(']</a>')
!
def namedLink(self, doc, level, output):
output('<a name="ref')
--- 190,194 ----
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
output(']</a>')
!
def namedLink(self, doc, level, output):
output('<a name="ref')
***************
*** 200,204 ****
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
output(']</a>')
!
def sgml(self,doc,level,output):
for c in doc.getChildNodes():
--- 199,203 ----
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
output(']</a>')
!
def sgml(self,doc,level,output):
for c in doc.getChildNodes():
***************
*** 208,212 ****
val = doc.getNodeValue()
output('<a href="#ref%s">[%s]</a>' % (val, val) )
!
def table(self,doc,level,output):
"""
--- 207,211 ----
val = doc.getNodeValue()
output('<a href="#ref%s">[%s]</a>' % (val, val) )
!
def table(self,doc,level,output):
"""
***************
*** 236,242 ****
output("</tr>\n")
output("</table>\n")
-
-
-
-
-
--- 235,236 ----
Index: HTMLWithImages.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/docstring/StructuredText/HTMLWithImages.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HTMLWithImages.py 8 Dec 2001 13:56:02 -0000 1.2
--- HTMLWithImages.py 25 Aug 2002 14:40:59 -0000 1.3
***************
*** 2,6 ****
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
--- 2,6 ----
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
! #
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
***************
*** 9,23 ****
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
! #
##############################################################################
- from string import join, split, find
- import re, sys, ST
- import time
from HTMLClass import HTMLClass
ets = HTMLClass.element_types
! ets.update({'StructuredTextImage': 'image'})
class HTMLWithImages(HTMLClass):
--- 9,20 ----
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
! #
##############################################################################
from HTMLClass import HTMLClass
ets = HTMLClass.element_types
! ets.update({'StructuredTextImage': 'image'})
class HTMLWithImages(HTMLClass):
***************
*** 25,56 ****
element_types = ets
- def document(self, doc, level, output):
- output('<html>\n')
- children=doc.getChildNodes()
- if (children and
- children[0].getNodeName() == 'StructuredTextSection'):
- output('<head>\n<title>%s</title>\n</head>\n' %
- children[0].getChildNodes()[0].getNodeValue())
- output('<body bgcolor="#FFFFFF">\n')
- for c in children:
- getattr(self, self.element_types[c.getNodeName()])(c, level, output)
- output('</body>\n')
- output('</html>\n')
def image(self, doc, level, output):
! if hasattr(doc, 'key'):
! output('<a name="%s"></a>\n' % doc.key)
! output('<img src="%s" alt="%s">\n' % (doc.href, doc.getNodeValue()))
! if doc.getNodeValue() and hasattr(doc, 'key'):
! output('<p><b>Figure %s</b> %s</p>\n' % (doc.key, doc.getNodeValue()))
!
! def xref(self, doc, level, output):
! val = doc.getNodeValue()
! output('<a href="#%s">Figure %s</a>' % (val, val) )
!
!
!
!
!
!
!
--- 22,30 ----
element_types = ets
def image(self, doc, level, output):
! if hasattr(doc, 'key'):
! output('<a name="%s"></a>\n' % doc.key)
! output('<img src="%s" alt="%s">\n' % (doc.href, doc.getNodeValue()))
! if doc.getNodeValue() and hasattr(doc, 'key'):
! output('<p><b>Figure %s</b> %s</p>\n' % (doc.key, doc.getNodeValue()))
Index: ST.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/docstring/StructuredText/ST.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ST.py 24 Oct 2001 21:27:35 -0000 1.1
--- ST.py 25 Aug 2002 14:40:59 -0000 1.2
***************
*** 1,4 ****
import re, STDOM
- from string import split, join, replace, expandtabs, strip, find
#####################################################################
--- 1,16 ----
+ ##############################################################################
+ #
+ # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
+ #
+ # This software is subject to the provisions of the Zope Public License,
+ # Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+ # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+ # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+ # FOR A PARTICULAR PURPOSE
+ #
+ ##############################################################################
+
import re, STDOM
#####################################################################
***************
*** 7,14 ****
def indention(str,front = re.compile("^\s+").match):
! """
Find the number of leading spaces. If none, return 0.
"""
!
result = front(str)
if result is not None:
--- 19,26 ----
def indention(str,front = re.compile("^\s+").match):
! """
Find the number of leading spaces. If none, return 0.
"""
!
result = front(str)
if result is not None:
***************
*** 37,41 ****
#print "parent for level ", level, " was => ", run.getColorizableTexts()
return run.getSubparagraphs()
!
def display(struct):
"""
--- 49,53 ----
#print "parent for level ", level, " was => ", run.getColorizableTexts()
return run.getSubparagraphs()
!
def display(struct):
"""
***************
*** 45,49 ****
the orignal paragraphs.
"""
!
if struct.getColorizableTexts():
print join(struct.getColorizableTexts()),"\n"
--- 57,61 ----
the orignal paragraphs.
"""
!
if struct.getColorizableTexts():
print join(struct.getColorizableTexts()),"\n"
***************
*** 51,55 ****
for x in struct.getSubparagraphs():
display(x)
!
def display2(struct):
"""
--- 63,67 ----
for x in struct.getSubparagraphs():
display(x)
!
def display2(struct):
"""
***************
*** 57,63 ****
the paragraphs. If the insertion works
correctly, display's results should mimic
! the orignal paragraphs.
"""
!
if struct.getNodeValue():
print struct.getNodeValue(),"\n"
--- 69,75 ----
the paragraphs. If the insertion works
correctly, display's results should mimic
! the orignal paragraphs.
"""
!
if struct.getNodeValue():
print struct.getNodeValue(),"\n"
***************
*** 65,69 ****
for x in struct.getSubparagraphs():
display(x)
!
def findlevel(levels,indent):
"""
--- 77,81 ----
for x in struct.getSubparagraphs():
display(x)
!
def findlevel(levels,indent):
"""
***************
*** 73,77 ****
paragraph
"""
!
keys = levels.keys()
for key in keys:
--- 85,89 ----
paragraph
"""
!
keys = levels.keys()
for key in keys:
***************
*** 98,102 ****
def StructuredText(paragraphs, delimiter=re.compile(para_delim)):
"""
! StructuredText accepts paragraphs, which is a list of
lines to be parsed. StructuredText creates a structure
which mimics the structure of the paragraphs.
--- 110,114 ----
def StructuredText(paragraphs, delimiter=re.compile(para_delim)):
"""
! StructuredText accepts paragraphs, which is a list of
lines to be parsed. StructuredText creates a structure
which mimics the structure of the paragraphs.
***************
*** 111,132 ****
run = struct
! 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
for paragraph in paragraphs:
ind.append([indention(paragraph), paragraph])
!
currentindent = indention(paragraphs[0])
levels[0] = currentindent
!
#############################################################
# updated #
#############################################################
!
for indent,paragraph in ind :
if indent == 0:
--- 123,144 ----
run = struct
! paragraphs = paragraphs.expandtabs()
paragraphs = '%s%s%s' % ('\n\n', paragraphs, '\n\n')
paragraphs = delimiter.split(paragraphs)
! paragraphs = [ x for x in paragraphs if x.strip() ]
if not paragraphs: return StructuredTextDocument()
!
ind = [] # structure based on indention levels
for paragraph in paragraphs:
ind.append([indention(paragraph), paragraph])
!
currentindent = indention(paragraphs[0])
levels[0] = currentindent
!
#############################################################
# updated #
#############################################################
!
for indent,paragraph in ind :
if indent == 0:
***************
*** 157,163 ****
else:
run = struct
! currentindet = indent
run.append(StructuredTextParagraph(paragraph, indent=indent, level=currentlevel))
!
return StructuredTextDocument(struct)
--- 169,175 ----
else:
run = struct
! currentindent = indent
run.append(StructuredTextParagraph(paragraph, indent=indent, level=currentlevel))
!
return StructuredTextDocument(struct)
***************
*** 172,176 ****
self._src=src
self._subs=list(subs)
!
self._attributes=kw.keys()
for k, v in kw.items(): setattr(self, k, v)
--- 184,188 ----
self._src=src
self._subs=list(subs)
!
self._attributes=kw.keys()
for k, v in kw.items(): setattr(self, k, v)
***************
*** 183,187 ****
def getAttribute(self, name):
return getattr(self, name, None)
!
def getAttributeNode(self, name):
if hasattr(self, name):
--- 195,199 ----
def getAttribute(self, name):
return getattr(self, name, None)
!
def getAttributeNode(self, name):
if hasattr(self, name):
***************
*** 214,218 ****
for p in self._subs: a(`p`)
a((' '*(self.indent or 0))+'])')
! return join(r,'\n')
"""
--- 226,230 ----
for p in self._subs: a(`p`)
a((' '*(self.indent or 0))+'])')
! return '\n'.join(r)
"""
***************
*** 222,229 ****
def _get_Children(self, type=type, lt=type([])):
return self.getChildren(type,lt)
!
def _get_Attribute(self, name):
return self.getAttribute(name)
!
def _get_AttributeNode(self, name):
return self.getAttributeNode(name)
--- 234,241 ----
def _get_Children(self, type=type, lt=type([])):
return self.getChildren(type,lt)
!
def _get_Attribute(self, name):
return self.getAttribute(name)
!
def _get_AttributeNode(self, name):
return self.getAttributeNode(name)
***************
*** 250,254 ****
"""
_attributes=()
!
def __init__(self, subs=None, **kw):
apply(StructuredTextParagraph.__init__,
--- 262,266 ----
"""
_attributes=()
!
def __init__(self, subs=None, **kw):
apply(StructuredTextParagraph.__init__,
***************
*** 258,265 ****
def getChildren(self...
[truncated message content] |