26 from logilab.mtconverter import (register_base_transforms, |
26 from logilab.mtconverter import (register_base_transforms, |
27 register_pil_transforms, |
27 register_pil_transforms, |
28 register_pygments_transforms) |
28 register_pygments_transforms) |
29 |
29 |
30 from cubicweb.utils import UStringIO |
30 from cubicweb.utils import UStringIO |
31 from cubicweb.uilib import rest_publish, html_publish |
31 from cubicweb.uilib import rest_publish, markdown_publish, html_publish |
32 |
32 |
33 HTML_MIMETYPES = ('text/html', 'text/xhtml', 'application/xhtml+xml') |
33 HTML_MIMETYPES = ('text/html', 'text/xhtml', 'application/xhtml+xml') |
34 |
34 |
35 # CubicWeb specific transformations |
35 # CubicWeb specific transformations |
36 |
36 |
37 class rest_to_html(Transform): |
37 class rest_to_html(Transform): |
38 inputs = ('text/rest', 'text/x-rst') |
38 inputs = ('text/rest', 'text/x-rst') |
39 output = 'text/html' |
39 output = 'text/html' |
40 def _convert(self, trdata): |
40 def _convert(self, trdata): |
41 return rest_publish(trdata.appobject, trdata.decode()) |
41 return rest_publish(trdata.appobject, trdata.decode()) |
|
42 |
|
43 class markdown_to_html(Transform): |
|
44 inputs = ('text/markdown', 'text/x-markdown') |
|
45 output = 'text/html' |
|
46 def _convert(self, trdata): |
|
47 return markdown_publish(trdata.appobject, trdata.decode()) |
42 |
48 |
43 class html_to_html(Transform): |
49 class html_to_html(Transform): |
44 inputs = HTML_MIMETYPES |
50 inputs = HTML_MIMETYPES |
45 output = 'text/html' |
51 output = 'text/html' |
46 def _convert(self, trdata): |
52 def _convert(self, trdata): |
51 |
57 |
52 mtconverter.UNICODE_POLICY = 'replace' |
58 mtconverter.UNICODE_POLICY = 'replace' |
53 |
59 |
54 ENGINE = TransformEngine() |
60 ENGINE = TransformEngine() |
55 ENGINE.add_transform(rest_to_html()) |
61 ENGINE.add_transform(rest_to_html()) |
|
62 ENGINE.add_transform(markdown_to_html()) |
56 ENGINE.add_transform(html_to_html()) |
63 ENGINE.add_transform(html_to_html()) |
57 |
64 |
58 try: |
65 try: |
59 from cubicweb.ext.tal import CubicWebContext, compile_template |
66 from cubicweb.ext.tal import CubicWebContext, compile_template |
60 except ImportError: |
67 except ImportError: |