Пример #1
0
 def test_image_with_key(self):
     doc = MockParagraph(key='abc', href='def', node_value='123')
     html = HTMLWithImages()
     l = []
     html.image(doc, 1, output=l.append)
     self.assertEqual(l,
                      ['<a name="abc"></a>\n',
                       '<img src="def" alt="123" />\n',
                       '<p><b>Figure abc</b> 123</p>\n'])
Пример #2
0
 def _test(self, stxtxt, expected):
     doc = stng.structurize(stxtxt)
     doc = DocumentWithImages()(doc)
     output = HTMLWithImages()(doc, level=1)
     if not expected in output:
         print "Text:     ", stxtxt.encode('utf-8')
         print "Converted:", output.encode('utf-8')
         print "Expected: ", expected.encode('utf-8')
         self.fail("'%s' not in result" % expected)        
Пример #3
0
 def _test(self, stxtxt, expected):
     from zope.structuredtext import stng
     from zope.structuredtext.document import DocumentWithImages
     from zope.structuredtext.html import HTMLWithImages
     doc = stng.structurize(stxtxt)
     doc = DocumentWithImages()(doc)
     output = HTMLWithImages()(doc, level=1)
     if not expected in output:
         print "Text:     ", stxtxt.encode('utf-8')
         print "Converted:", output.encode('utf-8')
         print "Expected: ", expected.encode('utf-8')
         self.fail("'%s' not in result" % expected)
Пример #4
0
 def _test(self, stxtxt, expected):
     from zope.structuredtext import stng
     from zope.structuredtext.document import DocumentWithImages
     from zope.structuredtext.html import HTMLWithImages
     doc = stng.structurize(stxtxt)
     doc = DocumentWithImages()(doc)
     output = HTMLWithImages()(doc, level=1)
     if not expected in output:
         print("Text:     ", stxtxt.encode('utf-8'))
         print("Converted:", output.encode('utf-8'))
         print("Expected: ", expected.encode('utf-8'))
         self.fail("'%s' not in result" % expected)        
Пример #5
0
    def test_paragraph_not_nestable(self):
        first_child_not_nestable = MockParagraph(node_name='not nestable or known')
        second_child_nestable = MockParagraph(node_name="#text")
        third_child_not_nestable = MockParagraph(node_name='not nestable or known')
        doc = MockParagraph(child_nodes=[first_child_not_nestable,
                                         second_child_nestable,
                                         third_child_not_nestable])

        html = HTMLWithImages()
        html.dispatch = lambda *args: None
        l = []
        html.paragraph(doc, level=1, output=l.append)
        self.assertEqual(l, ['<p>', '</p>\n', '<p>', '</p>\n'])
Пример #6
0
    def format(self,page,t):
        """
        Render some Structured Text as HTML, working around some quirks.
        """
        # an initial single word plus period becomes a numeric bullet -
        # prepend a temporary marker to prevent
        # XXX use locale/wikichars from Regexps.py instead of A-z
        # XXX not working ?
        t = re.sub(r'(?m)^([ \t]*)([A-z]\w*\.)',
                      r'\1<!--NOSTX-->\2',
                      t)
        # :: quoting fails if there is whitespace after the :: - remove it
        t = re.sub(r'(?m)::[ \t]+$', r'::', t)
        # suppress stx footnote handling so we can do it our way later
        t = re.sub(footnoteexpr,r'<a name="ref\1">![\1]</a>',t)
        t = re.sub(r'(?m)\[',r'[<!--NOSTX-->',t)
        # standard structured text can't handle unicode
        # it may not handle non-ascii either, so this could still fail
        t = page.toencoded(t)
        # let STX loose on it; don't let a formatter error break the whole page
        try:
            # XXX slow!
            t = HTMLWithImages(ZwikiDocumentWithImages(structurize(t)), level=2)
        except:
            BLATHER('Structured Text formatting failed: %s' \
                 % (formattedTraceback()))
            return '<pre>Structured Text formatting failed:\n%s</pre>' \
                   % (formattedTraceback())
        t = page.tounicode(t)

        # clean up
        t = re.sub(r'(<|&lt;)!--NOSTX--(>|&gt;)', r'', t)
        # strip html & body added by some zope versions
        t = re.sub(r'(?sm)^<html.*<body.*?>\n(.*)</body>\n</html>\n',r'\1',t)
        return t
Пример #7
0
    def get_docstring_html(self):
        doc = self.get_docstring()
        if doc.find('\n\n') > -1:
            doc = doc.split('\n\n')
            if len(doc) > 1:
                doc[1] = doc[1].strip()
            doc = '\n\n'.join(doc)

        doc = DocumentWithImages()(doc)
        return HTMLWithImages()(doc)
Пример #8
0
from common import *
from Products.ZWiki.i18n import _
from Products.ZWiki.plugins.pagetypes import registerPageType

from Globals import MessageDialog
try: # zope 2.10 and up uses zope3 stx
    from zope.structuredtext.stng         import structurize
    from zope.structuredtext.stng         import StructuredTextTable
    from zope.structuredtext.stng         import StructuredTextSGML
    from zope.structuredtext.document     import DocumentWithImages
    from zope.structuredtext.html         import HTMLWithImages
    HTMLWithImages = HTMLWithImages()
except ImportError: # zope 2.7-2.9
    from StructuredText                    import Basic as structurize
    from StructuredText                    import HTMLWithImages
    from StructuredText.DocumentWithImages import DocumentWithImages
    from StructuredText.DocumentClass      import StructuredTextTable
    from StructuredText.DocumentClass      import StructuredTextSGML

class PageTypeStx(PageTypeBaseHtml):
    _id = 'stx'
    _name = 'Structured Text'
    supportsStx = yes
    supportsWikiLinks = yes
    supportsHtml = yes
    supportsDtml = yes

    def format(self,page,t):
        """
        Render some Structured Text as HTML, working around some quirks.
        """
Пример #9
0
def stx2html(aStructuredString, level=1, header=1):
    st = structurize(aStructuredString)
    doc = DocumentWithImages()(st)
    return HTMLWithImages()(doc, header=header, level=level)
Пример #10
0
def stx2html(aStructuredString, level=1, header=1):
    """A shortcut to produce HTML. """
    st = structurize(aStructuredString)
    doc = DocumentWithImages()(st)
    return HTMLWithImages()(doc, header=header, level=level)