Commit e76730af authored by Paul Winkler's avatar Paul Winkler

refactoring: many methods contained duplicated code from dispatch().
also broke dispatch up into multiple lines for easier reading/debugging.
parent c2445f0b
...@@ -42,7 +42,10 @@ class HTMLClass: ...@@ -42,7 +42,10 @@ class HTMLClass:
def dispatch(self, doc, level, output): def dispatch(self, doc, level, output):
getattr(self, self.element_types[doc.getNodeName()])(doc, level, output) node_name = doc.getNodeName()
element_type = self.element_types[node_name]
element_method = getattr(self, element_type)
element_method(doc, level, output)
def __call__(self, doc, level=1, header=1): def __call__(self, doc, level=1, header=1):
r=[] r=[]
...@@ -55,7 +58,7 @@ class HTMLClass: ...@@ -55,7 +58,7 @@ class HTMLClass:
def document(self, doc, level, output): def document(self, doc, level, output):
children=doc.getChildNodes() children=doc.getChildNodes()
if self.header: if self.header:
output('<html>\n') output('<html>\n')
if (children and if (children and
...@@ -65,7 +68,7 @@ class HTMLClass: ...@@ -65,7 +68,7 @@ class HTMLClass:
output('<body>\n') output('<body>\n')
for c in children: for c in children:
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
if self.header: if self.header:
output('</body>\n') output('</body>\n')
...@@ -74,12 +77,13 @@ class HTMLClass: ...@@ -74,12 +77,13 @@ class HTMLClass:
def section(self, doc, level, output): def section(self, doc, level, output):
children=doc.getChildNodes() children=doc.getChildNodes()
for c in children: for c in children:
getattr(self, self.element_types[c.getNodeName()])(c, level+1, output) self.dispatch(c, level+1, output)
def sectionTitle(self, doc, level, output): def sectionTitle(self, doc, level, output):
output('<h%d>' % (level)) output('<h%d>' % (level))
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
output('</h%d>\n' % (level)) output('</h%d>\n' % (level))
def description(self, doc, level, output): def description(self, doc, level, output):
...@@ -87,7 +91,7 @@ class HTMLClass: ...@@ -87,7 +91,7 @@ class HTMLClass:
if p is None or p.getNodeName() is not doc.getNodeName(): if p is None or p.getNodeName() is not doc.getNodeName():
output('<dl>\n') output('<dl>\n')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
n=doc.getNextSibling() n=doc.getNextSibling()
if n is None or n.getNodeName() is not doc.getNodeName(): if n is None or n.getNodeName() is not doc.getNodeName():
output('</dl>\n') output('</dl>\n')
...@@ -95,13 +99,13 @@ class HTMLClass: ...@@ -95,13 +99,13 @@ class HTMLClass:
def descriptionTitle(self, doc, level, output): def descriptionTitle(self, doc, level, output):
output('<dt>') output('<dt>')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
output('</dt>\n') output('</dt>\n')
def descriptionBody(self, doc, level, output): def descriptionBody(self, doc, level, output):
output('<dd>') output('<dd>')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
output('</dd>\n') output('</dd>\n')
def bullet(self, doc, level, output): def bullet(self, doc, level, output):
...@@ -110,7 +114,7 @@ class HTMLClass: ...@@ -110,7 +114,7 @@ class HTMLClass:
output('\n<ul>\n') output('\n<ul>\n')
output('<li>') output('<li>')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
n=doc.getNextSibling() n=doc.getNextSibling()
output('</li>\n') output('</li>\n')
if n is None or n.getNodeName() is not doc.getNodeName(): if n is None or n.getNodeName() is not doc.getNodeName():
...@@ -122,7 +126,7 @@ class HTMLClass: ...@@ -122,7 +126,7 @@ class HTMLClass:
output('\n<ol>\n') output('\n<ol>\n')
output('<li>') output('<li>')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
n=doc.getNextSibling() n=doc.getNextSibling()
output('</li>\n') output('</li>\n')
if n is None or n.getNodeName() is not doc.getNodeName(): if n is None or n.getNodeName() is not doc.getNodeName():
...@@ -136,31 +140,28 @@ class HTMLClass: ...@@ -136,31 +140,28 @@ class HTMLClass:
output(escape(c.getNodeValue())) output(escape(c.getNodeValue()))
output('\n</pre>\n') output('\n</pre>\n')
else: else:
getattr(self, self.element_types[c.getNodeName()])( self.dispatch(c, level, output)
c, level, output)
def paragraph(self, doc, level, output): def paragraph(self, doc, level, output):
output('<p>') output('<p>')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
if c.getNodeName() in ['StructuredTextParagraph']: if c.getNodeName() in ['StructuredTextParagraph']:
getattr(self, self.element_types[c.getNodeName()])( self.dispatch(c, level, output)
c, level, output)
else: else:
getattr(self, self.element_types[c.getNodeName()])( self.dispatch(c, level, output)
c, level, output)
output('</p>\n') output('</p>\n')
def link(self, doc, level, output): def link(self, doc, level, output):
output('<a href="%s">' % doc.href) output('<a href="%s">' % doc.href)
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
output('</a>') output('</a>')
def emphasis(self, doc, level, output): def emphasis(self, doc, level, output):
output('<em>') output('<em>')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
output('</em>') output('</em>')
def literal(self, doc, level, output): def literal(self, doc, level, output):
...@@ -172,36 +173,36 @@ class HTMLClass: ...@@ -172,36 +173,36 @@ class HTMLClass:
def strong(self, doc, level, output): def strong(self, doc, level, output):
output('<strong>') output('<strong>')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
output('</strong>') output('</strong>')
def underline(self, doc, level, output): def underline(self, doc, level, output):
output("<u>") output("<u>")
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
output("</u>") output("</u>")
def innerLink(self, doc, level, output): def innerLink(self, doc, level, output):
output('<a href="#ref'); output('<a href="#ref');
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
output('">[') output('">[')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
output(']</a>') output(']</a>')
def namedLink(self, doc, level, output): def namedLink(self, doc, level, output):
output('<a name="ref') output('<a name="ref')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
output('">[') output('">[')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
output(']</a>') output(']</a>')
def sgml(self,doc,level,output): def sgml(self,doc,level,output):
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
def xref(self, doc, level, output): def xref(self, doc, level, output):
val = doc.getNodeValue() val = doc.getNodeValue()
...@@ -227,7 +228,7 @@ class HTMLClass: ...@@ -227,7 +228,7 @@ class HTMLClass:
str = '<td colspan="%s">' % column.getSpan() str = '<td colspan="%s">' % column.getSpan()
output(str) output(str)
for c in column.getChildNodes(): for c in column.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) self.dispatch(c, level, output)
if hasattr(column,"getType"): if hasattr(column,"getType"):
output("</"+column.getType()+">\n") output("</"+column.getType()+">\n")
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment