Commit 74c3de6f authored by Amos Latteier's avatar Amos Latteier

Updated docbook coverage to allow StructuredText to work. No more KeyErrors...

Updated docbook coverage to allow StructuredText to work. No more KeyErrors upon importing StructuredText. Also updated it to work with the current DocumentClass.py and with docbook 4.1.
parent 4ac681d1
......@@ -105,6 +105,7 @@ class DocBookClass:
'StructuredTextStrong': 'strong',
'StructuredTextLink': 'link',
'StructuredTextXref': 'xref',
'StructuredTextSGML': 'sgml',
}
def dispatch(self, doc, level, output):
......@@ -122,7 +123,7 @@ class DocBookClass:
output(lstrip(doc.getNodeValue()))
def document(self, doc, level, output):
output('<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V3.1//EN">\n')
output('<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN">\n')
output('<book>\n')
children=doc.getChildNodes()
if (children and
......@@ -133,16 +134,19 @@ class DocBookClass:
output('</book>\n')
def section(self, doc, level, output):
output('\n<sect%s>\n' % (level + 1))
output('\n<section>\n')
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))
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):
......@@ -208,7 +212,6 @@ class DocBookClass:
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()])(
......@@ -216,10 +219,10 @@ class DocBookClass:
output('</para>\n\n')
def link(self, doc, level, output):
# output('<link linkend="%s">' % doc.href)
output('<ulink url="%s">' % doc.href)
for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output)
# output('</link>')
output('</ulink>')
def emphasis(self, doc, level, output):
output('<emphasis>')
......@@ -240,7 +243,11 @@ class DocBookClass:
output('</emphasis>')
def xref(self, doc, level, output):
output('<xref linkend="%s">' % doc.getNodeValue())
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')
......@@ -256,7 +263,7 @@ def prestrip(v):
nlines=[]
for line in lines:
nlines.append(line[indent:])
return string.join(nlines, '\r\n')
return string.join(nlines, '\n')
class DocBookChapter(DocBookClass):
......@@ -290,12 +297,12 @@ class DocBookChapterWithFigures(DocBookChapter):
class DocBookArticle(DocBookClass):
def document(self, doc, level, output):
output('<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">\n')
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('<artheader>\n<title>%s</title>\n</artheader>\n' %
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)
......@@ -312,7 +319,7 @@ class DocBookBook:
self.chapters.append(chapter)
def read(self):
out = '<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V3.1//EN">\n<book>\n'
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'
......
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