[telepathy-doc/master] Attempt to support xref inside HTML
Davyd Madeley
davyd at madeley.id.au
Thu Apr 2 00:02:11 PDT 2009
---
docs/book/insert-examples.py | 43 ++++++++++++++--------------------------
docs/book/xslt/db2html.xsl.in | 4 ++-
2 files changed, 18 insertions(+), 29 deletions(-)
diff --git a/docs/book/insert-examples.py b/docs/book/insert-examples.py
index e336112..bb07006 100755
--- a/docs/book/insert-examples.py
+++ b/docs/book/insert-examples.py
@@ -119,6 +119,14 @@ for nicename in included_files:
except IOError, e:
print >> sys.stderr, e
continue
+
+ # syntax highlight the contents
+ if pygments:
+ # syntax highlighting
+ lexer = pygments.lexers.get_lexer_for_filename (filename)
+ contents = pygments.highlight (contents, lexer,
+ pygments.formatters.HtmlFormatter(noclasses=True))
+ contents = "<embedhtml>%s</embedhtml>" % contents
# find the starting offsets for each id in the file
def get_tuple (prefix, id):
@@ -128,37 +136,16 @@ for nicename in included_files:
else:
idx = m.span()[0]
return (idx, prefix, id, len (str))
- offsets = map (lambda id: get_tuple ('begin', id),
- included_files[nicename]) + \
- map (lambda id: get_tuple ('end', id),
- included_files[nicename])
- offsets.sort () # sort into ascending order
- pl = etree.SubElement (s, 'programlisting')
- cumoff = 0
- elem = None
-
- for (offset, prefix, id, l) in offsets:
- if offset is None: continue
-
- # append the CDATA to elem
- cdata = contents[cumoff:offset]
- if elem is not None: elem.tail = cdata
- else: pl.text = cdata
- cumoff = offset + l
+ for id in included_files[nicename]:
+ sre = re.compile ('(\\s)begin (%s)(\\s|$)' % re.escape (id), re.IGNORECASE)
+ contents = sre.sub(r'\1Begin <xref linkend="\2"/>\3', contents)
- # FIXME - I'd like something better than emphasis
- em = etree.Element ('emphasis')
- em.text = prefix.title () + " "
- etree.SubElement (em, 'xref', linkend=id)
- pl.append (em)
+ sre = re.compile ('(\\s)end (%s)(\\s|$)' % re.escape (id), re.IGNORECASE)
+ contents = sre.sub(r'\1End <xref linkend="\2"/>\3', contents)
- elem = em
-
- if elem is None:
- pl.text = contents[cumoff:]
- else:
- elem.tail = contents[cumoff:]
+ pl = etree.SubElement (s, 'programlisting')
+ pl.append (etree.XML (contents))
sys.stdout.write (etree.tostring (doc))
diff --git a/docs/book/xslt/db2html.xsl.in b/docs/book/xslt/db2html.xsl.in
index 2b27e9a..0036e8f 100644
--- a/docs/book/xslt/db2html.xsl.in
+++ b/docs/book/xslt/db2html.xsl.in
@@ -23,7 +23,9 @@
This allows us to embed XHTML directly into the output, e.g. from
a syntax highlighter -->
<xsl:template match="embedhtml">
- <xsl:copy-of select="./*"/>
+ <xsl:copy-of select="./*">
+ <xsl:call-template name="db2html.xref"/>
+ </xsl:copy-of>
</xsl:template>
<!-- the header to put at the top of every page -->
--
1.5.6.5
More information about the telepathy-commits
mailing list