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: ...@@ -105,6 +105,7 @@ class DocBookClass:
'StructuredTextStrong': 'strong', 'StructuredTextStrong': 'strong',
'StructuredTextLink': 'link', 'StructuredTextLink': 'link',
'StructuredTextXref': 'xref', 'StructuredTextXref': 'xref',
'StructuredTextSGML': 'sgml',
} }
def dispatch(self, doc, level, output): def dispatch(self, doc, level, output):
...@@ -122,7 +123,7 @@ class DocBookClass: ...@@ -122,7 +123,7 @@ class DocBookClass:
output(lstrip(doc.getNodeValue())) output(lstrip(doc.getNodeValue()))
def document(self, doc, level, output): 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') output('<book>\n')
children=doc.getChildNodes() children=doc.getChildNodes()
if (children and if (children and
...@@ -133,16 +134,19 @@ class DocBookClass: ...@@ -133,16 +134,19 @@ class DocBookClass:
output('</book>\n') output('</book>\n')
def section(self, doc, level, output): def section(self, doc, level, output):
output('\n<sect%s>\n' % (level + 1)) output('\n<section>\n')
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) 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): def sectionTitle(self, doc, level, output):
output('<title>') output('<title>')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
try:
getattr(self, self.element_types[c.getNodeName()])(c, level, output) getattr(self, self.element_types[c.getNodeName()])(c, level, output)
except:
print "failed", c.getNodeName(), c
output('</title>\n') output('</title>\n')
def description(self, doc, level, output): def description(self, doc, level, output):
...@@ -208,7 +212,6 @@ class DocBookClass: ...@@ -208,7 +212,6 @@ class DocBookClass:
c, level, output) c, level, output)
def paragraph(self, doc, level, output): def paragraph(self, doc, level, output):
output('<para>\n\n') output('<para>\n\n')
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])( getattr(self, self.element_types[c.getNodeName()])(
...@@ -216,10 +219,10 @@ class DocBookClass: ...@@ -216,10 +219,10 @@ class DocBookClass:
output('</para>\n\n') output('</para>\n\n')
def link(self, doc, level, output): def link(self, doc, level, output):
# output('<link linkend="%s">' % doc.href) output('<ulink url="%s">' % doc.href)
for c in doc.getChildNodes(): for c in doc.getChildNodes():
getattr(self, self.element_types[c.getNodeName()])(c, level, output) getattr(self, self.element_types[c.getNodeName()])(c, level, output)
# output('</link>') output('</ulink>')
def emphasis(self, doc, level, output): def emphasis(self, doc, level, output):
output('<emphasis>') output('<emphasis>')
...@@ -240,7 +243,11 @@ class DocBookClass: ...@@ -240,7 +243,11 @@ class DocBookClass:
output('</emphasis>') output('</emphasis>')
def xref(self, doc, level, output): 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): def prestrip(v):
v=string.replace(v, '\r\n', '\n') v=string.replace(v, '\r\n', '\n')
...@@ -256,7 +263,7 @@ def prestrip(v): ...@@ -256,7 +263,7 @@ def prestrip(v):
nlines=[] nlines=[]
for line in lines: for line in lines:
nlines.append(line[indent:]) nlines.append(line[indent:])
return string.join(nlines, '\r\n') return string.join(nlines, '\n')
class DocBookChapter(DocBookClass): class DocBookChapter(DocBookClass):
...@@ -290,12 +297,12 @@ class DocBookChapterWithFigures(DocBookChapter): ...@@ -290,12 +297,12 @@ class DocBookChapterWithFigures(DocBookChapter):
class DocBookArticle(DocBookClass): class DocBookArticle(DocBookClass):
def document(self, doc, level, output): 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') output('<article>\n')
children=doc.getChildNodes() children=doc.getChildNodes()
if (children and if (children and
children[0].getNodeName() == 'StructuredTextSection'): 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()) children[0].getChildNodes()[0].getNodeValue())
for c in children: for c in children:
getattr(self, self.element_types[c.getNodeName()])(c, level, output) getattr(self, self.element_types[c.getNodeName()])(c, level, output)
...@@ -312,7 +319,7 @@ class DocBookBook: ...@@ -312,7 +319,7 @@ class DocBookBook:
self.chapters.append(chapter) self.chapters.append(chapter)
def read(self): 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 out = out + '<title>%s</title>\n' % self.title
for chapter in self.chapters: for chapter in self.chapters:
out = out + chapter + '\n</book>\n' 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