author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 10 Sep 2009 08:02:52 +0200 | |
branch | stable |
changeset 3161 | 005f745315b0 |
parent 1977 | 606923dff11b |
child 4023 | eae23c40627a |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
0 | 1 |
"""mime type transformation engine for cubicweb, based on mtconverter |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
from logilab import mtconverter |
|
11 |
||
12 |
from logilab.mtconverter.engine import TransformEngine |
|
13 |
from logilab.mtconverter.transform import Transform |
|
14 |
from cubicweb.common.uilib import rest_publish, html_publish, remove_html_tags |
|
15 |
||
16 |
HTML_MIMETYPES = ('text/html', 'text/xhtml', 'application/xhtml+xml') |
|
17 |
# CubicWeb specific transformations |
|
18 |
||
19 |
class rest_to_html(Transform): |
|
20 |
inputs = ('text/rest', 'text/x-rst') |
|
21 |
output = 'text/html' |
|
22 |
def _convert(self, trdata): |
|
23 |
return rest_publish(trdata.appobject, trdata.decode()) |
|
24 |
||
25 |
class html_to_html(Transform): |
|
26 |
inputs = HTML_MIMETYPES |
|
27 |
output = 'text/html' |
|
28 |
def _convert(self, trdata): |
|
29 |
return html_publish(trdata.appobject, trdata.data) |
|
30 |
||
31 |
||
32 |
# Instantiate and configure the transformation engine |
|
33 |
||
34 |
mtconverter.UNICODE_POLICY = 'replace' |
|
35 |
||
36 |
ENGINE = TransformEngine() |
|
37 |
ENGINE.add_transform(rest_to_html()) |
|
38 |
ENGINE.add_transform(html_to_html()) |
|
39 |
||
40 |
HAS_PIL_TRANSFORMS = False |
|
41 |
HAS_PYGMENTS_TRANSFORMS = False |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
42 |
|
0 | 43 |
class html_to_text(Transform): |
44 |
inputs = HTML_MIMETYPES |
|
45 |
output = 'text/plain' |
|
46 |
def _convert(self, trdata): |
|
47 |
return remove_html_tags(trdata.data) |
|
48 |
ENGINE.add_transform(html_to_text()) |