def testRegressionsTests(self):
        """ HTML regression test """

        for f in files:
            Doc  = DocumentClass.DocumentClass()
            HTML = HTMLClass.HTMLClass()
            raw_text = readFile(regressions,f)
            text = Doc(ST.StructuredText(raw_text))
            html = HTML(text)

            reg_fname = f.replace('.stx','.ref')
            reg_html  = readFile(regressions , reg_fname)

            if reg_html.strip()!= html.strip():

                IO = cStringIO.StringIO()

                oldStdout = sys.stdout
                sys.stdout = IO

                try:
                    open('_tmpout','w').write(html)
                    ndiff.fcompare(os.path.join(regressions,reg_fname),
                                   '_tmpout')
                    os.unlink('_tmpout')
                finally:
                    sys.stdout = oldStdout

                raise AssertionError, \
                    'HTML regression test failed on %s\nDiff:\n%s\n' % (f,
                     IO.getvalue())
Example #2
0
    def testRegressionsTests(self):
        """ HTML regression test """

        for f in files:
            Doc = DocumentClass.DocumentClass()
            HTML = HTMLClass.HTMLClass()
            raw_text = readFile(regressions, f)
            text = Doc(ST.StructuredText(raw_text))
            html = HTML(text)

            reg_fname = f.replace('.stx', '.ref')
            reg_html = readFile(regressions, reg_fname)

            if reg_html.strip() != html.strip():

                IO = cStringIO.StringIO()

                oldStdout = sys.stdout
                sys.stdout = IO

                try:
                    open('_tmpout', 'w').write(html)
                    ndiff.fcompare(os.path.join(regressions, reg_fname),
                                   '_tmpout')
                    os.unlink('_tmpout')
                finally:
                    sys.stdout = oldStdout

                raise AssertionError, \
                    'HTML regression test failed on %s\nDiff:\n%s\n' % (f,
                     IO.getvalue())
Example #3
0
    def CookedBody(self, stx_level=None, setlevel=0, rest_level=None):
        """ Get the "cooked" (ready for presentation) form of the text.

        The prepared basic rendering of an object.  For Documents, this
        means pre-rendered structured text, or what was between the
        <BODY> tags of HTML.

        If the format is html, and 'stx_level' or 'rest_level' are not 
        passed in or is the same as the object's current settings, return 
        the cached cooked text.  Otherwise, recook.  If we recook and 
        'setlevel' is true, then set the recooked text and stx_level or 
        rest_level on the object.
        """
        if ((self.text_format == 'html' or self.text_format == 'plain' or
             (stx_level is None) or (stx_level == self._stx_level)) and
            ((rest_level is None) or (rest_level == self._rest_level))):
            return self.cooked_text
        elif rest_level is not None:
            cooked = ReST(self.text, initial_header_level=rest_level)
            if setlevel:
                self._rest_level = rest_level
                self.cooked_text = cooked
            return cooked
        else:
            cooked = HTML(self.text, level=stx_level, header=0)
            if setlevel:
                self._stx_level = stx_level
                self.cooked_text = cooked
            return cooked
Example #4
0
def format_stx( text, level=1 ):
    """ Render STX to HTML.
    """
    warn('format_stx() will be removed in CMF 1.6. Please use '
         'StructuredText.StructuredText.HTML instead.',
         DeprecationWarning)
    return HTML(text, level=level, header=0)
Example #5
0
    def _edit(self, text):
        """ Edit the Document and cook the body.
        """
        self._size = len(text)

        text_format = self.text_format
        if not text_format:
            text_format = self.text_format

        if text_format != 'html':
            normalizer = queryUtility(ILinebreakNormalizer)

            if normalizer is not None:
                self.text = normalizer.normalizeIncoming(self, text)
            else:
                self.text = text
        else:
            self.text = text

        if text_format == 'html':
            self.cooked_text = text
        elif text_format == 'plain':
            self.cooked_text = html_quote(text).replace('\n', '<br />')
        elif text_format == 'restructured-text':
            self.cooked_text = ReST(text,
                                    initial_header_level=self._rest_level)
        else:
            self.cooked_text = HTML(text, level=self._stx_level, header=0)
Example #6
0
    def testClassicHTMLDocumentClass(self):
        """ testing HTML ClassicDocumentClass"""

        for f in files:
            Doc = ClassicDocumentClass.DocumentClass()
            HTML = HTMLClass.HTMLClass()
            raw_text = readFile(regressions, f)
            text = Doc(ST.StructuredText(raw_text))
            assert HTML(text),\
                'HTML ClassicDocumentClass failed on %s' % f
    def _test(self,stxtxt , expected):

        if not isinstance(stxtxt, UnicodeType):
            res = HTML(stxtxt,level=1,header=0)
            if res.find(expected)==-1:
                print "Text:     ",stxtxt
                print "Converted:",res
                print "Expected: ",expected
                raise AssertionError,"basic test failed for '%s'" % stxtxt

        if isinstance(stxtxt, UnicodeType):
            ustxtxt = stxtxt
        else:
            ustxtxt = unicode(stxtxt)
        res = HTML(ustxtxt,level=1,header=0)
        if res.find(expected)==-1:
            print "Text:     ",stxtxt.encode('latin-1')
            print "Converted:",res.encode('latin-1')
            print "Expected: ",expected.encode('latin-1')
            raise AssertionError, ("basic test failed for Unicode '%s'"
                                   % stxtxt)
Example #8
0
    def _edit(self, text):
        """ Edit the Document and cook the body.
        """
        self.text = text
        self._size = len(text)

        text_format = self.text_format
        if text_format == 'html':
            self.cooked_text = text
        elif text_format == 'plain':
            self.cooked_text = html_quote(text).replace('\n', '<br />')
        else:
            self.cooked_text = HTML(text, level=self._stx_level, header=0)
Example #9
0
    def _test(self, stxtxt, expected):

        if not isinstance(stxtxt, UnicodeType):
            res = HTML(stxtxt, level=1, header=0)
            if not expected in res:
                print "Text:     ", stxtxt
                print "Converted:", res
                print "Expected: ", expected
                raise AssertionError, "basic test failed for '%s'" % stxtxt

        if isinstance(stxtxt, UnicodeType):
            ustxtxt = stxtxt
        else:
            ustxtxt = unicode(stxtxt)

        res = HTML(ustxtxt, level=1, header=0)
        if not expected in res:

            print "Text:     ", stxtxt.encode('latin-1')
            print "Converted:", res.encode('latin-1')
            print "Expected: ", expected.encode('latin-1')
            raise AssertionError, ("basic test failed for Unicode '%s'" %
                                   stxtxt)
Example #10
0
    def CookedBody(self, stx_level=None, setlevel=0):
        """\
        The prepared basic rendering of an object.  For Documents, this
        means pre-rendered structured text, or what was between the
        <BODY> tags of HTML.

        If the format is html, and 'stx_level' is not passed in or is the
        same as the object's current settings, return the cached cooked
        text.  Otherwise, recook.  If we recook and 'setlevel' is true,
        then set the recooked text and stx_level on the object.
        """
        if (self.text_format == 'html' or self.text_format == 'plain'
                or (stx_level is None) or (stx_level == self._stx_level)):
            return self.cooked_text
        else:
            cooked = HTML(self.text, level=stx_level, header=0)
            if setlevel:
                self._stx_level = stx_level
                self.cooked_text = cooked
            return cooked
Example #11
0
    def _edit(self, text, text_format='', safety_belt=''):
        """ Edit the Document and cook the body.
        """
        if not self._safety_belt_update(safety_belt=safety_belt):
            msg = ("Intervening changes from elsewhere detected."
                   " Please refetch the document and reapply your changes."
                   " (You may be able to recover your version using the"
                   " browser 'back' button, but will have to apply them"
                   " to a freshly fetched copy.)")
            raise EditingConflict(msg)

        self.text = text

        if not text_format:
            text_format = self.text_format
        if text_format == 'html':
            self.cooked_text = text
        elif text_format == 'plain':
            self.cooked_text = html_quote(text).replace('\n', '<br />')
        else:
            self.cooked_text = HTML(text, level=self._stx_level, header=0)
Example #12
0
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################

import os, sys
from StructuredText.StructuredText import HTML

if len(sys.argv) > 1:
    files = sys.argv[1:]
else:
    files = os.listdir('.')
    files = filter(lambda x: x.endswith('.stx'), files)

for f in files:

    data = open(f, 'r').read()
    html = HTML(data)

    outfile = f.replace('.stx', '.ref')
    open(outfile, 'w').write(html)
Example #13
0
 def cook( self ):
     if not hasattr( self, '_v_cooked' ):
         self._v_cooked = HTML(self.raw, level=1, header=0)
     return self._v_cooked