Commit b544b5d7 authored by Amos Latteier's avatar Amos Latteier

Added support for x-refs and fixed image support including x-refs to figures.

parent 3451d7f6
...@@ -338,6 +338,8 @@ class StructuredTextSGML(StructuredTextMarkup): pass ...@@ -338,6 +338,8 @@ class StructuredTextSGML(StructuredTextMarkup): pass
class StructuredTextLink(StructuredTextMarkup): pass class StructuredTextLink(StructuredTextMarkup): pass
class StructuredTextXref(StructuredTextMarkup): pass
class DocumentClass: class DocumentClass:
""" """
Class instance calls [ex.=> x()] require a structured text Class instance calls [ex.=> x()] require a structured text
...@@ -368,7 +370,8 @@ class DocumentClass: ...@@ -368,7 +370,8 @@ class DocumentClass:
'doc_strong', 'doc_strong',
'doc_emphasize', 'doc_emphasize',
'doc_literal', 'doc_literal',
'doc_sgml' 'doc_sgml',
'doc_xref',
] ]
def __call__(self, doc): def __call__(self, doc):
...@@ -976,3 +979,18 @@ class DocumentClass: ...@@ -976,3 +979,18 @@ class DocumentClass:
start,end = r.span() start,end = r.span()
text = s[start:end] text = s[start:end]
return (StructuredTextSGML(text),start,end) return (StructuredTextSGML(text),start,end)
def doc_xref(self, s,
expr = re.compile('\[([a-zA-Z0-9\-.:/;,\n\~]+)\]').search
):
r = expr(s)
if r:
start, end = r.span(1)
return (StructuredTextXref(s[start:end]), start-1, end+1)
else:
return None
...@@ -109,21 +109,16 @@ class HTMLWithImages(HTMLClass): ...@@ -109,21 +109,16 @@ class HTMLWithImages(HTMLClass):
output('</body>\n') output('</body>\n')
output('</html>\n') output('</html>\n')
def image(self, doc, level, output):
output('<img src="%s" alt="%s">' % (doc.href, doc.getNodeValue()))
def image(self, doc, level, output): def image(self, doc, level, output):
if hasattr(doc, 'key'): if hasattr(doc, 'key'):
output('<a name="%s"></a>\n<img src="%s" alt="%s">' % (doc.key, doc.href, doc.getNodeValue())) output('<a name="%s"></a>\n' % doc.key)
else: output('<img src="%s" alt="%s">\n' % (doc.href, doc.getNodeValue()))
output('<img src="%s" alt="%s">' % (doc.href, doc.getNodeValue())) if doc.getNodeValue() and hasattr(doc, 'key'):
output('<p><b>Figure %s</b> %s</p>\n' % (doc.key, doc.getNodeValue()))
def xref(self, doc, level, output): def xref(self, doc, level, output):
val = doc.getNodeValue() val = doc.getNodeValue()
output('<a href="#%s">%s</a>' % (val, val) ) output('<a href="#%s">Figure %s</a>' % (val, val) )
......
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