Пример #1
0
    def _makeHtml(self, page):
        style = Style()
        stylepath = style.getPageStyle(page)

        try:
            tpl = HtmlTemplate(readTextFile(stylepath))
        except EnvironmentError:
            tpl = HtmlTemplate(readTextFile(style.getDefaultStyle()))

        content = self._changeContentByEvent(page,
                                             PreprocessingParams(page.content),
                                             self._application.onPreprocessing)

        if page.autoLineWrap:
            content = self._changeContentByEvent(
                page, PreHtmlImprovingParams(content),
                self._application.onPreHtmlImproving)

            config = HtmlRenderConfig(self._application.config)
            improverFactory = HtmlImproverFactory(self._application)
            text = improverFactory[config.HTMLImprover.value].run(content)
        else:
            text = content

        userhead = u"<title>{}</title>".format(page.title)
        result = tpl.substitute(content=text, userhead=userhead)

        result = self._changeContentByEvent(page, PostprocessingParams(result),
                                            self._application.onPostprocessing)
        return result
Пример #2
0
    def testImproved1(self):
        src = """<ul><li>Несортированный список. Элемент 1</li><li>Несортированный список. Элемент 2</li><li>Несортированный список. Элемент 3</li><ol><li>Вложенный сортированный список. Элемент 1</li><li>Вложенный сортированный список. Элемент 2</li><li>Вложенный сортированный список. Элемент 3</li><li>Вложенный сортированный список. Элемент 4</li><ul><li>Совсем вложенный сортированный список. Элемент 1</li><li>Совсем вложенный сортированный список. Элемент 2</li></ul><li>Вложенный сортированный список. Элемент 5</li></ol><ul><li>Вложенный несортированный список. Элемент 1</li></ul></ul>"""

        expectedResult = """<ul>
<li>Несортированный список. Элемент 1</li>
<li>Несортированный список. Элемент 2</li>
<li>Несортированный список. Элемент 3</li>
<ol>
<li>Вложенный сортированный список. Элемент 1</li>
<li>Вложенный сортированный список. Элемент 2</li>
<li>Вложенный сортированный список. Элемент 3</li>
<li>Вложенный сортированный список. Элемент 4</li>
<ul>
<li>Совсем вложенный сортированный список. Элемент 1</li>
<li>Совсем вложенный сортированный список. Элемент 2</li>
</ul>
<li>Вложенный сортированный список. Элемент 5</li>
</ol>
<ul>
<li>Вложенный несортированный список. Элемент 1</li>
</ul>
</ul>"""

        templatepath = os.path.join(getTemplatesDir(), "__default",
                                    "__style.html")
        tpl = HtmlTemplate(readTextFile(templatepath).strip())

        result = tpl.substitute(BrHtmlImprover().run(src))
        self.assertIn(expectedResult, result)
Пример #3
0
    def testChangeFontSize(self):
        self.config.fontSize.value = 20
        content = "бла-бла-бла"
        templatepath = os.path.join(getTemplatesDir(), "__default",
                                    "__style.html")
        tpl = HtmlTemplate(readTextFile(templatepath).strip())
        result = tpl.substitute(content=content)

        self.assertIn("font-size:20pt;", result)
Пример #4
0
    def test_text_08(self):
        content = "бла-бла-бла"
        style = "$content $title"

        result_right = "бла-бла-бла Заголовок"

        tpl = HtmlTemplate(style)
        result = tpl.substitute(content=content, title='Заголовок')

        self.assertEqual(result, result_right)
Пример #5
0
    def test_text_04(self):
        content = u"бла-бла-бла"
        style = u"$userstyle $content $"

        result_right = u" бла-бла-бла $"

        tpl = HtmlTemplate(style)
        result = tpl.substitute(content=content)

        self.assertEqual(result, result_right)
Пример #6
0
    def test_text_01(self):
        content = "бла-бла-бла"
        style = "$userstyle $userhead $content"

        result_right = "  бла-бла-бла"

        tpl = HtmlTemplate(style)
        result = tpl.substitute(content=content)

        self.assertEqual(result, result_right)
Пример #7
0
    def testChangeFontName(self):
        self.config.fontName.value = u"Arial"
        content = u"бла-бла-бла"

        templatepath = os.path.join(getTemplatesDir(), "__default",
                                    "__style.html")
        tpl = HtmlTemplate(readTextFile(templatepath).strip())
        result = tpl.substitute(content=content)

        self.assertIn(u"font-family:Arial;", result)
Пример #8
0
    def test_text_06(self):
        content = "бла-бла-бла"
        style = "$userstyle $content $$ $unknown"

        result_right = " бла-бла-бла $$ $unknown"

        tpl = HtmlTemplate(style)
        result = tpl.substitute(content=content)

        self.assertEqual(result, result_right)
Пример #9
0
    def makeHtml(self, stylepath):
        parser = Parser()
        css = parser.getCSS()
        head = u'<style>\n{}\n</style>'.format(css)

        html = parser.convert(self.page.content)
        tpl = HtmlTemplate(readTextFile(stylepath))
        result = tpl.substitute(content=html,
                                userhead=head,
                                title=self.page.display_title)
        return result
Пример #10
0
    def makeHtml(self, stylepath):
        parser = Parser()
        content = parser.convert(self.page.content)

        text = BrHtmlImprover().run(content)
        head = u""

        tpl = HtmlTemplate(readTextFile(stylepath))

        result = tpl.substitute(content=text, userhead=head)

        return result
Пример #11
0
    def generateHtml(self, page):
        path = self.getHtmlPath()

        if page.readonly and os.path.exists(path):
            # Если страница открыта только для чтения и html-файл уже существует, то покажем его
            return readTextFile(path)

        style = Style()
        stylepath = style.getPageStyle(page)

        try:
            tpl = HtmlTemplate(readTextFile(stylepath))
        except:
            MessageBox(_(u"Page style Error. Style by default is used"),
                       _(u"Error"), wx.ICON_ERROR | wx.OK)

            tpl = HtmlTemplate(readTextFile(style.getDefaultStyle()))

        content = self._changeContentByEvent(self.page,
                                             PreprocessingParams(page.content),
                                             Application.onPreprocessing)

        if page.autoLineWrap:
            content = self._changeContentByEvent(
                self.page, PreHtmlImprovingParams(content),
                Application.onPreHtmlImproving)

            config = HtmlRenderConfig(Application.config)
            improverFactory = HtmlImproverFactory(Application)
            text = improverFactory[config.HTMLImprover.value].run(content)
        else:
            text = content

        userhead = u"<title>{}</title>".format(page.title)
        result = tpl.substitute(content=text, userhead=userhead)

        result = self._changeContentByEvent(self.page,
                                            PostprocessingParams(result),
                                            Application.onPostprocessing)
        return result
Пример #12
0
    def testChangeUserStyleRussian(self):
        style = u"p {background-color: maroon; /* Цвет фона под текстом параграфа */ color: white; /* Цвет текста */ }"

        self.config.userStyle.value = style

        content = u"бла-бла-бла"

        templatepath = os.path.join(getTemplatesDir(), "__default",
                                    "__style.html")
        tpl = HtmlTemplate(readTextFile(templatepath).strip())
        result = tpl.substitute(content=content)

        self.assertTrue(style in result, result)
Пример #13
0
    def testDefault(self):
        content = "бла-бла-бла"
        result_right = r"""<body>
бла-бла-бла
</body>
</html>"""

        templatepath = os.path.join(getTemplatesDir(), "__default",
                                    "__style.html")
        tpl = HtmlTemplate(readTextFile(templatepath).strip())
        result = tpl.substitute(content=content)

        self.assertIn(result_right, result.replace("\r\n", "\n"))
Пример #14
0
    def testChangeUserStyle(self):
        style = "p {background-color: maroon; color: white; }"

        self.config.userStyle.value = style

        content = "бла-бла-бла"

        templatepath = os.path.join(getTemplatesDir(), "__default",
                                    "__style.html")
        tpl = HtmlTemplate(readTextFile(templatepath).strip())
        result = tpl.substitute(content=content)

        self.assertTrue(style in result, result)
Пример #15
0
    def makeHtml(self, stylepath):
        parser = Parser()
        css = parser.getCSS()
        head = u'<style>\n{}\n</style>'.format(css)

        html = parser.convert(self.page.content)
        tpl = HtmlTemplate(readTextFile(stylepath))
        if Version(*outwiker.core.__version__) >= Version(1, 5):
            result = tpl.substitute(content=html,
                                    userhead=head,
                                    title=self.page.display_title)
        else:
            result = tpl.substitute(content=html, userhead=head)
        return result
Пример #16
0
    def testImproved2(self):
        src = r"""<h2>Attach links</h2>Attach:file.odt<br><a href="__attach/file.odt">file.odt</a><br><a href="__attach/file.odt">alternative text</a><br><a href="__attach/file with spaces.pdf">file with spaces.pdf</a><h2>Images</h2>"""

        expectedResult = r"""<h2>Attach links</h2>
Attach:file.odt<br>
<a href="__attach/file.odt">file.odt</a><br>
<a href="__attach/file.odt">alternative text</a><br>
<a href="__attach/file with spaces.pdf">file with spaces.pdf</a>
<h2>Images</h2>"""

        templatepath = os.path.join(getTemplatesDir(), "__default",
                                    "__style.html")
        tpl = HtmlTemplate(readTextFile(templatepath).strip())

        result = tpl.substitute(BrHtmlImprover().run(src))
        self.assertIn(expectedResult, result)
Пример #17
0
    def makeHtml(self, stylepath):
        # Get content
        content = (self.page.content
                   if self.page.content
                   else EmptyContent(Application.config).content)

        content = self._changeContentByEvent(self.page,
                                             PreprocessingParams(content),
                                             Application.onPreprocessing)

        # Create parser
        factory = ParserFactory()
        parser = factory.make(self.page, Application.config)

        config = HtmlRenderConfig(Application.config)

        # Parse wiki content
        html = parser.toHtml(content)
        if parser.footer:
            html += u'\n' + parser.footer

        # Improve HTML
        html = self._changeContentByEvent(self.page,
                                          PreHtmlImprovingParams(html),
                                          Application.onPreHtmlImproving)

        improverFactory = HtmlImproverFactory(Application)
        text = improverFactory[config.HTMLImprover.value].run(html)
        head = parser.head

        # Create final HTML file
        tpl = HtmlTemplate(readTextFile(stylepath))
        result = tpl.substitute(content=text,
                                userhead=head,
                                title=self.page.display_title)

        result = self._changeContentByEvent(self.page,
                                            PostprocessingParams(result),
                                            Application.onPostprocessing)

        return result
Пример #18
0
 def makeHtml(self, stylepath):
     head = u""
     html = Parser().convert(self.page.content)
     tpl = HtmlTemplate(readTextFile(stylepath))
     result = tpl.substitute(content=html, userhead=head)
     return result