MacroBazaar: docbook.py
| File docbook.py, 558 bytes (added by simon@…, 7 years ago) |
|---|
| Line | |
|---|---|
| 1 | import trac.util |
| 2 | import libxml2, libxslt |
| 3 | |
| 4 | def execute(hdf, text, env): |
| 5 | stylesheet = env.get_config('docbook', 'stylesheet') |
| 6 | if not stylesheet: |
| 7 | raise trac.util.TracError('DocBook stylesheet not configured.') |
| 8 | else: |
| 9 | style = libxslt.parseStylesheetDoc(libxml2.parseFile(stylesheet)) |
| 10 | doc = libxml2.parseDoc(text) |
| 11 | result = style.applyStylesheet(doc, None) |
| 12 | result_string = style.saveResultToString(result) |
| 13 | style.freeStylesheet() |
| 14 | doc.freeDoc() |
| 15 | result.freeDoc() |
| 16 | return result_string |
