| 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 | html = style.saveResultToString(result) |
|---|
| 13 | style.freeStylesheet() |
|---|
| 14 | doc.freeDoc() |
|---|
| 15 | result.freeDoc() |
|---|
| 16 | return html[html.find('<body>')+6:html.find('</body>')].strip() |
|---|