1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from Products.PortalTransforms.interfaces import ITransform
from zope.interface import implements
from reStructuredText import HTML
import sys
class rest:
r"""Converts from reST to HTML.
>>> transform = rest()
>>> class D:
... def setData(self, data):
... self.value = data
>>> data = transform.convert('*hello world*', D())
>>> print data.value
<p><em>hello world</em></p>
<BLANKLINE>
We want the 'raw' and 'include' directives to be disabled by
default:
>>> try:
... out = transform.convert('.. raw:: html\n :file: <isonum.txt>', D())
... except NotImplementedError:
... print 'Good'
... else:
... if ""raw" directive disabled." in out.value:
... print 'Good'
... else:
... print 'Failure'
Good
>>> try:
... out = transform.convert('.. include:: <isonum.txt>', D())
... except NotImplementedError:
... print 'Good'
... else:
... if ""include" directive disabled." in out.value:
... print 'Good'
... else:
... print 'Failure'
Good
"""
implements(ITransform)
__name__ = "rest_to_html"
inputs = ("text/x-rst", "text/restructured",)
output = "text/html"
def name(self):
return self.__name__
def convert(self, orig, data, **kwargs):
# do the format
encoding = kwargs.get('encoding', 'utf-8')
input_encoding = kwargs.get('input_encoding', encoding)
output_encoding = kwargs.get('output_encoding', encoding)
language = kwargs.get('language', 'en')
warnings = kwargs.get('warnings', None)
settings = {'documentclass': '',
'traceback': 1,
}
html = HTML(orig,
report_level=2,
input_encoding=input_encoding,
output_encoding=output_encoding,
language_code=language,
warnings=warnings,
settings=settings)
html = html.replace(' class="document"', '', 1)
data.setData(html)
return data
def register():
return rest()