[Zope-Checkins] CVS: Zope2 - ClassicDocumentClass.py:1.3.6.1 DocBookClass.py:1.2.6.1 DocumentClass.py:1.5.6.2 STDOM.py:1.2.6.1 __init__.py:1.4.4.1
Brian Lloyd
brian@digiciool.com
Wed, 14 Mar 2001 14:17:51 -0500 (EST)
Update of /cvs-repository/Zope2/lib/python/StructuredText
In directory korak:/home/brian/temp/zope-23-branch/lib/python/StructuredText
Modified Files:
Tag: zope-2_3-branch
ClassicDocumentClass.py DocBookClass.py DocumentClass.py
STDOM.py __init__.py
Log Message:
Merged a bunch of changes not merged from trunk to branch
--- Updated File ClassicDocumentClass.py in package Zope2 --
--- ClassicDocumentClass.py 2001/01/05 22:10:15 1.3
+++ ClassicDocumentClass.py 2001/03/14 19:17:50 1.3.6.1
@@ -138,6 +138,12 @@
(self, StructuredTextSectionTitle(src), subs),
kw)
+ def getColorizableTexts(self):
+ return self._src.getColorizableTexts()
+
+ def setColorizableTexts(self,src):
+ self._src.setColorizableTexts(src)
+
# a StructuredTextTable holds StructuredTextRows
class StructuredTextTable(ST.StructuredTextDocument):
"""
@@ -563,9 +569,9 @@
def doc_literal(
self, s,
expr=re.compile(
- "(?:\s|^)'" # open
+ "(?:\s|^)'" # open
"([^ \t\n\r\f\v']|[^ \t\n\r\f\v'][^\n']*[^ \t\n\r\f\v'])" # contents
- "'(?:\s|[,.;:!?]|$)" # close
+ "'(?:\s|[,.;:!?]|$)" # close
).search):
r=expr(s)
@@ -577,7 +583,7 @@
def doc_emphasize(
self, s,
- expr = re.compile('\s*\*([ \na-zA-Z0-9.:/;,\'\"\?]+)\*(?!\*|-)').search
+ expr = re.compile('\s*\*([ \na-zA-Z0-9.:/;,\'\"\?\=\-\>\<\(\)]+)\*(?!\*|-)').search
):
r=expr(s)
@@ -650,8 +656,8 @@
def doc_href(
self, s,
- expr1 = re.compile("(\"[ a-zA-Z0-9\n\-\.\,\;\(\)\/\:\/]+\")(:)([a-zA-Z0-9\:\/\.\~\-]+)([,]*\s*)").search,
- expr2 = re.compile('(\"[ a-zA-Z0-9\n\-\.\:\;\(\)\/]+\")([,]+\s+)([a-zA-Z0-9\@\.\,\?\!\/\:\;\-\#]+)(\s*)').search):
+ expr1 = re.compile("(\"[ a-zA-Z0-9\n\-\.\,\;\(\)\/\:\/\*\']+\")(:)([a-zA-Z0-9\:\/\.\~\-]+)([,]*\s*)").search,
+ expr2 = re.compile('(\"[ a-zA-Z0-9\n\-\.\:\;\(\)\/\*\']+\")([,]+\s+)([a-zA-Z0-9\@\.\,\?\!\/\:\;\-\#]+)(\s*)').search):
#expr1=re.compile('\"([ a-zA-Z0-9.:/;,\n\~\(\)\-]+)\"'
# ':'
--- Updated File DocBookClass.py in package Zope2 --
--- DocBookClass.py 2001/01/04 15:01:59 1.2
+++ DocBookClass.py 2001/03/14 19:17:50 1.2.6.1
@@ -88,238 +88,245 @@
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',
- }
-
- 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 V3.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<sect%s>\n' % (level + 1))
- children=doc.getChildNodes()
- for c in children:
- getattr(self, self.element_types[c.getNodeName()])(c, level+1, output)
- output('\n</sect%s>\n' % (level + 1))
-
- def sectionTitle(self, doc, level, output):
- output('<title>')
- for c in doc.getChildNodes():
- getattr(self, self.element_types[c.getNodeName()])(c, level, output)
- 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():
+ 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)
- output('</para>\n\n')
-
- def link(self, doc, level, output):
-# output('<link linkend="%s">' % doc.href)
- for c in doc.getChildNodes():
- getattr(self, self.element_types[c.getNodeName()])(c, level, output)
-# output('</link>')
+ c, level, output)
- 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 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 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 xref(self, doc, level, output):
- output('<xref linkend="%s">' % 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, '\r\n')
+ 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')
+ 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'})
+ets.update({'StructuredTextImage': 'image'})
class DocBookChapterWithFigures(DocBookChapter):
- element_types = ets
+ element_types = ets
- 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)
+ 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 V3.1//EN">\n')
- output('<article>\n')
- children=doc.getChildNodes()
- if (children and
- children[0].getNodeName() == 'StructuredTextSection'):
- output('<artheader>\n<title>%s</title>\n</artheader>\n' %
- children[0].getChildNodes()[0].getNodeValue())
- for c in children:
- getattr(self, self.element_types[c.getNodeName()])(c, level, output)
- output('</article>\n')
+ 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 V3.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()
-
+ 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()
+
--- Updated File DocumentClass.py in package Zope2 --
--- DocumentClass.py 2001/03/07 21:32:04 1.5.6.1
+++ DocumentClass.py 2001/03/14 19:17:50 1.5.6.2
@@ -89,15 +89,25 @@
StringType=type('')
ListType=type([])
+def flatten(obj, append):
+ if obj.getNodeType()==STDOM.TEXT_NODE:
+ append(obj.getNodeValue())
+ else:
+ for child in obj.getChildNodes():
+ flatten(child, append)
+
+
class StructuredTextExample(ST.StructuredTextParagraph):
"""Represents a section of document with literal text, as for examples"""
def __init__(self, subs, **kw):
- t=[]; a=t.append
- for s in subs: a(s.getNodeValue())
- apply(ST.StructuredTextParagraph.__init__,
- (self, join(t,'\n\n'), ()),
- kw)
+ t=[]
+ a=t.append
+ for s in subs:
+ flatten(s, a)
+ apply(ST.StructuredTextParagraph.__init__,
+ (self, join(t,'\n\n'), ()),
+ kw)
def getColorizableTexts(self): return ()
def setColorizableTexts(self, src): pass # never color examples
@@ -137,7 +147,13 @@
apply(ST.StructuredTextParagraph.__init__,
(self, StructuredTextSectionTitle(src), subs),
kw)
-
+
+ def getColorizableTexts(self):
+ return self._src.getColorizableTexts()
+
+ def setColorizableTexts(self,src):
+ self._src.setColorizableTexts(src)
+
# a StructuredTextTable holds StructuredTextRows
class StructuredTextTable(ST.StructuredTextParagraph):
"""
@@ -846,7 +862,7 @@
def doc_emphasize(
self, s,
- expr = re.compile(r'\s*\*([ \na-zA-Z0-9.:/;,\'\"\?\-\_\/\=]+)\*(?!\*|-)').search
+ expr = re.compile(r'\s*\*([ \na-zA-Z0-9.:/;,\'\"\?\-\_\/\=\-\>\<\(\)]+)\*(?!\*|-)').search
):
r=expr(s)
@@ -916,7 +932,7 @@
return None
## Some constants to make the doc_href() regex easier to read.
- _DQUOTEDTEXT = r'("[ a-zA-Z0-9\n\-\.\,\;\(\)\/\:\/]+")' ## double quoted text
+ _DQUOTEDTEXT = r'("[ a-zA-Z0-9\n\-\.\,\;\(\)\/\:\/\*\']+")' ## double quoted text
_URL_AND_PUNC = r'([a-zA-Z0-9\@\.\,\?\!\/\:\;\-\#\~]+)'
_SPACES = r'(\s*)'
--- Updated File STDOM.py in package Zope2 --
--- STDOM.py 2001/01/04 15:01:59 1.2
+++ STDOM.py 2001/03/14 19:17:50 1.2.6.1
@@ -178,7 +178,7 @@
if not children:
return None
- n=chidren[0]
+ n=children[0]
if type(n) is st:
n=TextNode(n)
@@ -554,7 +554,7 @@
return self.getNodeType()
def _get_NodeValue(self, type=type, st=type('')):
- return self.GetNodeValue(type,st)
+ return self.getNodeValue(type,st)
def _get_ParentNode(self):
return self.getParentNode()
--- Updated File __init__.py in package Zope2 --
--- __init__.py 2001/01/04 15:01:59 1.4
+++ __init__.py 2001/03/14 19:17:50 1.4.4.1
@@ -104,7 +104,7 @@
DocumentWithImages=DocumentWithImages.DocumentWithImages()
HTMLWithImages=HTMLWithImages.HTMLWithImages()
-DocBookBook=DocBookClass.DocBookBook
+DocBookBook=DocBookClass.DocBookBook()
DocBookChapter=DocBookClass.DocBookChapter()
DocBookChapterWithFigures=DocBookClass.DocBookChapterWithFigures()
DocBookArticle=DocBookClass.DocBookArticle()