• Julien Muchembled's avatar
    PortalTransforms: merge upstream revision 10366 (17/01/09) · 4adafd42
    Julien Muchembled authored
    Conflicts:
    	Products/PortalTransforms/Extensions/Install.py
    	Products/PortalTransforms/HISTORY.txt
    	Products/PortalTransforms/Transform.py
    	Products/PortalTransforms/TransformEngine.py
    	Products/PortalTransforms/chain.py
    	Products/PortalTransforms/configure.zcml
    	Products/PortalTransforms/data.py
    	Products/PortalTransforms/interfaces.py
    	Products/PortalTransforms/libtransforms/commandtransform.py
    	Products/PortalTransforms/libtransforms/piltransform.py
    	Products/PortalTransforms/libtransforms/retransform.py
    	Products/PortalTransforms/tests/test_engine.py
    	Products/PortalTransforms/tests/test_transforms.py
    	Products/PortalTransforms/transforms/broken.py
    	Products/PortalTransforms/transforms/html_body.py
    	Products/PortalTransforms/transforms/identity.py
    	Products/PortalTransforms/transforms/image_to_html.py
    	Products/PortalTransforms/transforms/lynx_dump.py
    	Products/PortalTransforms/transforms/markdown_to_html.py
    	Products/PortalTransforms/transforms/pdf_to_html.py
    	Products/PortalTransforms/transforms/pdf_to_text.py
    	Products/PortalTransforms/transforms/python.py
    	Products/PortalTransforms/transforms/rest.py
    	Products/PortalTransforms/transforms/rtf_to_html.py
    	Products/PortalTransforms/transforms/rtf_to_xml.py
    	Products/PortalTransforms/transforms/safe_html.py
    	Products/PortalTransforms/transforms/st.py
    	Products/PortalTransforms/transforms/text_pre_to_html.py
    	Products/PortalTransforms/transforms/text_to_html.py
    	Products/PortalTransforms/transforms/textile_to_html.py
    	Products/PortalTransforms/transforms/word_to_html.py
    	Products/PortalTransforms/unsafe_transforms/command.py
    	Products/PortalTransforms/unsafe_transforms/xml.py
    	Products/PortalTransforms/utils.py
    	Products/PortalTransforms/version.txt
    
    git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41725 20353a03-c40f-0410-a6d1-a30d3c3de9de
    4adafd42
rest.py 2.25 KB
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 "&quot;raw&quot; 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 "&quot;include&quot; 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()