author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 20 Jan 2010 11:31:38 +0100 | |
changeset 4290 | c2f15166f019 |
parent 4252 | 6c4f109c2b03 |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
0 | 1 |
"""mime type transformation engine for cubicweb, based on mtconverter |
2 |
||
3 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
4 |
:copyright: 2001-2010 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 |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
14 |
from cubicweb.uilib import rest_publish, html_publish, remove_html_tags |
0 | 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()) |