예제 #1
0
    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)

        initial_header_level = int(self.config.get('initial_header_level', 2))
        report_level = int(self.config.get('report_level', 2))

        settings = {
            'documentclass': '',
            'traceback': 1,
        }

        html = HTML(orig,
                    input_encoding=input_encoding,
                    output_encoding=output_encoding,
                    language_code=language,
                    initial_header_level=initial_header_level,
                    report_level=report_level,
                    warnings=warnings,
                    settings=settings)

        html = html.replace(' class="document"', '', 1)
        data.setData(html)
        return data
    def fCompositeCookedBodyForElement(self,
                                       theElement,
                                       stx_level=None,
                                       setlevel=0,
                                       theTimeProfilingResults=None):

        if (theElement == None):
            return '\n<em>No Element</em><br/>\n\n'

        # From CMFDefault.Document.py see Products.PortalTransforms.Transforms.rest.py

        anEditableBody = self.fCompositeEditableBodyForElement(theElement)
        if not anEditableBody:
            return "\n<em>No EditableBody obtained for %s</em><br/>\n\n" % str(
                self)

        aCookedBody = HTML(anEditableBody,
                           initial_header_level=1,
                           input_encoding='utf-8',
                           output_encoding='utf-8')

        if not anEditableBody:
            return "\n<em>Empty HTML obtained for CookedBody for %s</em>\n\n" % str(
                self)

        aCookedBodyReClassed = aCookedBody.replace('class="docutils"',
                                                   'class="listing"').replace(
                                                       'class="head"',
                                                       'class="nosort"')

        return aCookedBodyReClassed
예제 #3
0
    def test_raw_directive_url_option_raises(self):
        source = '.. raw:: html\n  :url: http://www.zope.org'
        result = HTML(source)

        # The raw: directive hasn't been rendered, it remains
        # verbatimly in the rendered output.  Instead a warning
        # message is presented:
        self.assert_(source in result)
        self.assert_(docutils_raw_warning in result)
예제 #4
0
    def test_raw_directive_file_option_raises(self):
        source = '.. raw:: html\n  :file: inclusion.txt'
        result = HTML(source)

        # The raw: directive hasn't been rendered, it remains
        # verbatimly in the rendered output.  Instead a warning
        # message is presented:
        self.assert_(source in result)
        self.assert_(docutils_raw_warning in result)
예제 #5
0
    def test_include_directive_raises(self):
        directive = '.. include:: /etc/passwd'
        source = 'hello world\n %s' % directive
        result = HTML(source)

        # The include: directive hasn't been rendered, it remains
        # verbatimly in the rendered output.  Instead a warning
        # message is presented:
        self.assert_(directive in result)
        self.assert_(docutils_include_warning in result)
예제 #6
0
    def test_raw_directive_disabled(self):
        EXPECTED = '<h1>HELLO WORLD</h1>'
        source = '.. raw:: html\n\n  %s\n' % EXPECTED
        result = HTML(source)  # don't raise, but don't work either

        # The raw: directive hasn't been rendered, it remains
        # verbatimly in the rendered output.  Instead a warning
        # message is presented:
        self.assert_(EXPECTED not in result)
        self.assert_(cgi.escape(EXPECTED) in result)
        self.assert_(docutils_raw_warning in result)
예제 #7
0
    def test_raw_directive_disabled(self):

        EXPECTED = '<h1>HELLO WORLD</h1>'

        source = '.. raw:: html\n\n  %s\n' % EXPECTED
        result = HTML(source)  # don't raise, but don't work either
        self.failIf(EXPECTED in result)

        self.failUnless("&quot;raw&quot; directive disabled" in result)
        from cgi import escape
        self.failUnless(escape(EXPECTED) in result)
예제 #8
0
    def readMeHtml(self):
        """Renders README.txt (in rst) inside the page"""

        opd = os.path.dirname
        readme_path = os.path.join(os.path.abspath(opd(opd(__file__))),
                                   'README.txt')
        readme_html = HTML(file(readme_path).read(),
                           report_level=100)  # No errors/warnings -> faster
        # F*****g header changes the base href, so we need to tweak all href="#..."
        actual_url = self.request.URL
        return readme_html.replace('href="#', 'href="%s#' % actual_url)
예제 #9
0
    def testWithSingleSubtitle(self):
        input = '''
title
-----
subtitle
++++++++
text
'''
        expected = '''<h3 class="title">title</h3>
<h4 class="subtitle">subtitle</h4>
<p>text</p>
'''
        output = HTML(input)
        self.assertEquals(output, expected)
예제 #10
0
    def testHeaderLevel(self):

        encoding = 'iso-8859-15'
        for level in range(0, 5):
            html = HTML(txt,
                        input_encoding=encoding,
                        output_encoding=encoding,
                        initial_header_level=level)

            expected = '<h%d>Hello World</h%d>' % (level + 1, level + 1)
            self.assertEqual(expected in html, True)

            expected = '<h%d>Von Vögeln und Öfen</h%d>' % (level + 1,
                                                             level + 1)
            self.assertEqual(expected in html, True)
예제 #11
0
def restructured_text(v, name='(Unknown name)', md={}):
    try:
        from reStructuredText import HTML
    except ImportError:
        logger.info('The reStructuredText package is not available, therefor '
                    'the DT_Var.restructured_text function returns None.')
        return None

    if isinstance(v, str):
        txt = v
    elif aq_base(v).meta_type in ['DTML Document', 'DTML Method']:
        txt = aq_base(v).read_raw()
    else:
        txt = str(v)

    return HTML(txt)
예제 #12
0
    def testHeaderLevel(self):

        encoding = 'iso-8859-15'
        for level in range(0, 5):
            html = HTML(txt,
                        input_encoding=encoding,
                        output_encoding=encoding,
                        initial_header_level=level)

            expected = '<h%d><a id="hello-world" name="hello-world">Hello World</a></h%d>' %\
                        (level+1, level+1)
            self.assertEqual(expected in html, True)

            expected = '<h%d><a id="von-v-geln-und-fen" name="von-v-geln-und-fen">Von Vögeln und Öfen</a></h%d>' %\
                        (level+1, level+1)
            self.assertEqual(expected in html, True)
예제 #13
0
def construct_multipart_from_stx(from_addr,
                                 to_addr,
                                 subject,
                                 body,
                                 other_headers=None,
                                 encoding='utf8'):
    """All inputs to this method are expected to be unicode or ascii.

    This converts the input text to html using the stx converter

        >>> m = construct_multipart_from_stx(u'*****@*****.**',
        ...     u'*****@*****.**',
        ...     u'Un Subj\xc3\xa9t',
        ...     u'A simple body with some non ascii t\xc3\xa9xt with "a link":http://www.example.com')
        >>> print m.as_string() #doctest: +ELLIPSIS
        Content-Type: multipart/alternative; boundary="..."
        MIME-Version: 1.0
        From: [email protected]
        To: [email protected]
        Subject: Un =?utf8?b?U3ViasODwql0?=
        <BLANKLINE>
        --...
        Content-Type: text/plain; charset="utf8"
        MIME-Version: 1.0
        Content-Transfer-Encoding: quoted-printable
        Content-Disposition: inline
        <BLANKLINE>
        A simple body with some non ascii t=C3=83=C2=A9xt with "a link":http://www.=
        example.com
        --...
        Content-Type: text/html; charset="utf8"
        MIME-Version: 1.0
        Content-Transfer-Encoding: quoted-printable
        Content-Disposition: inline
        <BLANKLINE>
        <p>A simple body with some non ascii t=C3=83=C2=A9xt with <a href=3D"http:/=
        /www.example.com">a link</a></p>
        <BLANKLINE>
        --...
    """
    if other_headers is None:
        other_headers = {}
    html = HTML(body, level=2, header=0)
    return construct_multipart(from_addr, to_addr, subject, body, html,
                               other_headers, encoding)
예제 #14
0
def structured_text(v, name='(Unknown name)', md={}):
    from zope.structuredtext.html import HTML

    if isinstance(v, str):
        txt = v
    elif aq_base(v).meta_type in ['DTML Document', 'DTML Method']:
        txt = aq_base(v).read_raw()
    else:
        txt = str(v)

    level = 3
    try:
        from App.config import getConfiguration
    except ImportError:
        pass
    else:
        level = getConfiguration().structured_text_header_level

    doc = DocumentWithImages()(txt)
    return HTML()(doc, level, header=False)
    def fCookedBodyForElement(self,
                              theTimeProfilingResults=None,
                              theElement=None,
                              stx_level=None,
                              setlevel=0,
                              theAdditionalParams=None):
        """Retrieve an HTML presentation of an element's content as a Textual view.
        
        """

        if (theElement == None):
            return '\n<em>No Element</em><br/>\n\n'

        # From CMFDefault.Document.py see Products.PortalTransforms.Transforms.rest.py

        anEditableBody = self.fEditableBodyForElement(theTimeProfilingResults,
                                                      theElement,
                                                      theTimeProfilingResults)
        if not anEditableBody:
            return "\n<em>No EditableBody obtained for %s</em><br/>\n\n" % str(
                self)

        aCookedBody = HTML(anEditableBody,
                           initial_header_level=1,
                           input_encoding='utf-8',
                           output_encoding='utf-8')

        if not anEditableBody:
            return "\n<em>Empty HTML obtained for CookedBody for %s</em>\n\n" % str(
                self)

        aCookedBodyReClassed = aCookedBody.replace('class="docutils"',
                                                   'class="listing"').replace(
                                                       'class="head"',
                                                       'class="nosort"')

        return aCookedBodyReClassed
예제 #16
0
 def test_csv_table_file_option_raise(self):
     source = '.. csv-table:: \n  :file: inclusion.txt'
     result = HTML(source)
     self.assertTrue('File and URL access deactivated' in result)
예제 #17
0
 def _test(txt, in_enc, out_enc):
     return HTML(txt, input_encoding=in_enc, output_encoding=out_enc)
예제 #18
0
 def test_csv_table_url_option_raise(self):
     source = '.. csv-table:: \n  :url: http://www.evil.org'
     result = HTML(source)
     self.assertTrue('File and URL access deactivated' in result)