Skip to content

Commit

Permalink
Unify the way lists are handled in output. Getting coverage to 89.12%
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Aug 21, 2017
1 parent 7b13550 commit 36bd864
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 40 deletions.
23 changes: 8 additions & 15 deletions src/zope/structuredtext/docbook.py
Expand Up @@ -114,10 +114,10 @@ def descriptionBody(self, doc, level, output):
output('</para></listitem>\n')
output('</varlistentry>\n')

def bullet(self, doc, level, output):
def _list(self, doc, level, output, list_tag):
p = doc.getPreviousSibling()
if p is None or p.getNodeName() is not doc.getNodeName():
output('<itemizedlist>\n')
output('<' + list_tag + '>\n')
output('<listitem><para>\n')

for c in doc.getChildNodes():
Expand All @@ -126,20 +126,13 @@ def bullet(self, doc, level, output):
n = doc.getNextSibling()
output('</para></listitem>\n')
if n is None or n.getNodeName() is not doc.getNodeName():
output('</itemizedlist>\n')
output('</' + list_tag + '>\n')

def bullet(self, doc, level, output):
self._list(doc, level, output, 'itemizedlist')

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')
self._list(doc, level, output, 'orderedlist')

def example(self, doc, level, output):
i = 0
Expand Down Expand Up @@ -253,7 +246,7 @@ def document(self, doc, level, output):

class DocBookChapterWithFigures(DocBookChapter):

element_types = DocBook.element_types
element_types = DocBook.element_types.copy()
element_types.update({'StructuredTextImage': 'image'})

def image(self, doc, level, output):
Expand Down
34 changes: 9 additions & 25 deletions src/zope/structuredtext/html.py
Expand Up @@ -113,45 +113,29 @@ def descriptionBody(self, doc, level, output):
)(c, level, output)
output('</dd>\n')

def _list(self, doc, level, output, list_tag=None):
def _list(self, doc, level, output, list_tag, item_tag='li'):
p = doc.getPreviousSibling()
if p is None or p.getNodeName() != doc.getNodeName():
output('\n<' + list_tag + '>\n')
output('<li>')
if item_tag:
output('<' + item_tag + '>')
for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()]
)(c, level, output)
n = doc.getNextSibling()
output('</li>\n')
if item_tag:
output('</' + item_tag + '>\n')
if n is None or n.getNodeName() != doc.getNodeName():
output('\n</' + list_tag + '\n')
output('\n</' + list_tag + '>\n')

def description(self, doc, level, output):
p = doc.getPreviousSibling()
if p is None or p.getNodeName() != 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() != doc.getNodeName():
output('</dl>\n')
self._list(doc, level, output, 'dl', item_tag=None)

def bullet(self, doc, level, output):
self._list(doc, level, output, "<ul>")
self._list(doc, level, output, "ul")

def numbered(self, doc, level, output):
p = doc.getPreviousSibling()
if p is None or p.getNodeName() != 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() != doc.getNodeName():
output('\n</ol>\n')
self._list(doc, level, output, "ol")

def example(self, doc, level, output):
i = 0
Expand Down
2 changes: 2 additions & 0 deletions src/zope/structuredtext/regressions/Acquisition.ref
Expand Up @@ -232,6 +232,7 @@
<p> If desired, the current rules for looking up attributes in complex
expressions can best be understood through repeated application of
the <code>__of__</code> method:</p>

<dl>
<dt> <code>a.x</code></dt>
<dd><code>x.__of__(a)</code></dd>
Expand All @@ -243,6 +244,7 @@
<dd><code>c.__of__(b.__of__(a))</code></dd>
<dt> <code>a.b.c.x</code></dt>
<dd><code>x.__of__(a).__of__(b.__of__(a)).__of__(c.__of__(b.__of__(a)))</code></dd>

</dl>
<p> and by keeping in mind that attribute lookup in a wrapper
is done by trying to lookup the attribute in the wrapped object
Expand Down
2 changes: 2 additions & 0 deletions src/zope/structuredtext/regressions/ExtensionClass.ref
Expand Up @@ -194,6 +194,7 @@
<h3> Meta Information</h3>
<p> Like standard python classes, extension classes have the following
attributes containing meta-data:</p>

<dl>
<dt> <code>__doc__</code></dt>
<dd>a documentation string for the class,</dd>
Expand All @@ -206,6 +207,7 @@
<dt> <code>__module__</code></dt>
<dd>the name of the module in which the class was
defined. </dd>

</dl>
<p> The class dictionary provides access to unbound methods and their
documentation strings, including extension methods and special
Expand Down
2 changes: 2 additions & 0 deletions src/zope/structuredtext/regressions/examples.ref
Expand Up @@ -31,6 +31,7 @@
<p><a name="ref1">[1]</a> (The referring text should be a paragraph, not a header, and
should contain a reference to this footnote, footnote "<a href="#ref1">[1]</a>".)</p>
<p> Some hrefs, in a definition list:</p>

<dl>
<dt> <u>Regular</u></dt>
<dd><a href="http://www.zope.org">http://www.zope.org/</a></dd>
Expand All @@ -40,6 +41,7 @@ should contain a reference to this footnote, footnote "<a href="#ref1">[1]</a>".
<dd><a href=":locallink">locallink</a></dd>
<dt> <u>W protocol implicit</u>, alternate</dt>
<dd>"locallink", :locallink</dd>

</dl>
<p> |||| A Simple Two-column Table ||
|| Column A || Column B ||
Expand Down

0 comments on commit 36bd864

Please sign in to comment.