[ZCM] [ZC] 1045/ 2 Comment "Need to be able to create table of
contents in structured text"
Collector: Zope Bugs, Features,
and Patches ...
zope-coders-admin at zope.org
Mon Sep 29 08:55:32 EDT 2003
Issue #1045 Update (Comment) "Need to be able to create table of contents in structured text"
Status Pending, Zope/feature+solution medium
To followup, visit:
http://collector.zope.org/Zope/1045
==============================================================
= Comment - Entry #2 by ajung on Sep 29, 2003 8:55 am
Could you please resubmit the patch as dedicated file?
________________________________________
= Request - Entry #1 by Anonymous User on Sep 10, 2003 3:36 pm
We've been using plone for a while now for various software development docs, and the one real annoyance was that we couldn't automatically create a table of contents when using structured text. For a while I tried using apt, and then uploading the html --- but that was a bit of a pain, so I took a look at the StructuredText classes, and it was actually really easy to add...
Basically I just dump html anchors in front of each section title, and then a paragraph consisting solely of "TOC:" is replaced by a table of contents... At the moment only top level sections are added to the table of contents --- I found larger docs hard to read otherwise... This could be extended a lot --- adding section numbers and maybe a table to pretty up the TOC itself, but this patch seemed to be enough for me...
Damn --- I don't have a user id on the collector, so I can't attache the patch... It's really short, so I'm just going to paste it in here... If this thing wraps the lines or something annoying like that - drop me an email, and I can email the patch in...
diff -ur Zope-2.6.0/lib/python/StructuredText/DocumentClass.py /home/warren/tmp/Zope-2.6.0-linux2-x86/lib/python/StructuredText/DocumentClass.py
--- Zope-2.6.0/lib/python/StructuredText/DocumentClass.py 2002-12-31 16:41:02.000000000 -0500
+++ /home/warren/tmp/Zope-2.6.0-linux2-x86/lib/python/StructuredText/DocumentClass.py 2002-09-18 10:54:12.000000000 -0400
@@ -72,7 +72,6 @@
class StructuredTextSection(ST.StructuredTextParagraph):
"""Represents a section of a document with a title and a body"""
-
def __init__(self, src, subs=None, **kw):
apply(ST.StructuredTextParagraph.__init__,
(self, StructuredTextSectionTitle(src), subs),
diff -ur Zope-2.6.0/lib/python/StructuredText/HTMLClass.py /home/warren/tmp/Zope-2.6.0-linux2-x86/lib/python/StructuredText/HTMLClass.py
--- Zope-2.6.0/lib/python/StructuredText/HTMLClass.py 2003-01-03 13:58:40.000000000 -0500
+++ /home/warren/tmp/Zope-2.6.0-linux2-x86/lib/python/StructuredText/HTMLClass.py 2002-08-14 17:58:22.000000000 -0400
@@ -77,7 +77,6 @@
getattr(self, self.element_types[c.getNodeName()])(c, level+1, output)
def sectionTitle(self, doc, level, output):
- output('<a name="%s"> </a>' % doc.getNodeValue());
output('<h%d>' % (level))
for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
@@ -142,31 +141,15 @@
def paragraph(self, doc, level, output):
- if re.match("TOC:", doc.getNodeValue()):
- siblings=doc.getParentNode().getChildNodes();
- output('<h3> Table of Contents</h3>\n');
- output('<ul>\n');
- tocNum = 1;
- for s in siblings:
- if s.getNodeName() == 'StructuredTextSection' :
- output('<li> ')
- title = s.getChildNodes()[0].getNodeValue()
- output('<a href="#' + title + '">' + title + "</a>");
- output('</li>\n')
-
- output('</ul>\n')
-
- else:
-
- output('<p>')
- for c in doc.getChildNodes():
- if c.getNodeName() in ['StructuredTextParagraph']:
- getattr(self, self.element_types[c.getNodeName()])(
- c, level, output)
- else:
- getattr(self, self.element_types[c.getNodeName()])(
- c, level, output)
- output('</p>\n')
+ output('<p>')
+ for c in doc.getChildNodes():
+ if c.getNodeName() in ['StructuredTextParagraph']:
+ getattr(self, self.element_types[c.getNodeName()])(
+ c, level, output)
+ else:
+ getattr(self, self.element_types[c.getNodeName()])(
+ c, level, output)
+ output('</p>\n')
def link(self, doc, level, output):
output('<a href="%s">' % doc.href)
==============================================================
More information about the Zope-Collector-Monitor
mailing list