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
def generateHtml (self, page): path = self.getHtmlPath (page) if page.readonly and os.path.exists (path): # Если страница открыта только для чтения и html-файл уже существует, то покажем его return path style = Style() stylepath = style.getPageStyle (page) try: tpl = HtmlTemplate (stylepath) except: MessageBox (_(u"Page style Error. Style by default is used"), _(u"Error"), wx.ICON_ERROR | wx.OK) tpl = HtmlTemplate (style.getDefaultStyle()) if page.autoLineWrap: text = HtmlImprover.run (page.content) text = re.sub ("\n<br>\n(<li>)|(<li>)", "\n<LI>", text) else: text = page.content result = tpl.substitute (content=text) with open (path, "wb") as fp: fp.write (result.encode ("utf-8")) return path
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
def makeHtml (self, stylepath): path = self.getResultPath() if self.canReadFromCache(): return path factory = ParserFactory () parser = factory.make(self.page, Application.config) content = self.page.content if len (self.page.content) > 0 else self._generateEmptyContent (parser) text = HtmlImprover.run (parser.toHtml (content) ) head = parser.head tpl = HtmlTemplate (stylepath) result = tpl.substitute (content=text, userhead=head) with open (path, "wb") as fp: fp.write (result.encode ("utf-8")) try: self._getHashOption().value = self.getHash() except IOError: # Не самая страшная потеря, если не сохранится хэш. # Максимум, что грозит пользователю, каждый раз генерить старницу pass return path
def testImproved1 (self): src = u"""<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 = u"""<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)
def testChangeFontSize (self): self.config.fontSize.value = 20 content = u"бла-бла-бла" result_right = u"""<!DOCTYPE html> <html> <head> <meta http-equiv='X-UA-Compatible' content='IE=edge' /> <meta http-equiv='content-type' content='text/html; charset=utf-8'/> <style type='text/css'> body, div, p, table { font-size:20pt; font-family:Verdana; } img{border:none} </style> </head> <body> <p>бла-бла-бла</p> </body> </html>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (content=content) self.assertEqual (result, result_right, result)
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 result = tpl.substitute(content=text, title=page.display_title) result = self._changeContentByEvent(page, PostprocessingParams(result), self._application.onPostprocessing) return result
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)
def testChangeFontSize (self): self.config.fontSize.value = 20 content = u"бла-бла-бла" result_right = u"""<!DOCTYPE html> <HTML> <HEAD> <META HTTP-EQUIV='X-UA-Compatible' CONTENT='IE=edge' /> <META HTTP-EQUIV='CONTENT-TYPE' CONTENT='TEXT/HTML; CHARSET=UTF-8'/> <STYLE type='text/css'> body, div, p, table { font-size:20pt; font-family:Verdana; } img{border:none} </STYLE> </HEAD> <BODY> <P>бла-бла-бла</P> </BODY> </HTML>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (content=content) self.assertEqual (result, result_right, result)
def testChangeFontSize (self): self.config.fontSize.value = 20 content = u"бла-бла-бла" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (readTextFile (templatepath).strip()) result = tpl.substitute (content=content) self.assertIn (u"font-size:20pt;", result)
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)
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)
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)
def test_text_02(self): content = "бла-бла-бла" style = "$userstyle $userhead $content $unknown" result_right = " бла-бла-бла $unknown" tpl = HtmlTemplate(style) result = tpl.substitute(content=content) self.assertEqual(result, result_right)
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)
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)
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)
def test_text_05 (self): content = u"бла-бла-бла" style = u"$userstyle $content $$" result_right = u" бла-бла-бла $$" tpl = HtmlTemplate (style) result = tpl.substitute (content=content) self.assertEqual (result, result_right)
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
def testChangeFontName(self): self.config.fontName.value = "Arial" content = "бла-бла-бла" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertIn("font-family:Arial;", result)
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
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
def testDefault (self): content = u"бла-бла-бла" result_right = ur"""<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"))
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 (templatepath) result = tpl.substitute (content=content) self.assertTrue (style in result, result)
def testChangeUserStyle (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 (templatepath) result = tpl.substitute (content=content) self.assertTrue (style in result, result)
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)
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)
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"))
def testImproved1 (self): src = u"""<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 = u"""<!DOCTYPE html> <html> <head> <meta http-equiv='X-UA-Compatible' content='IE=edge' /> <meta http-equiv='content-type' content='text/html; charset=utf-8'/> <style type='text/css'> body, div, p, table { font-size:10pt; font-family:Verdana; } img{border:none} </style> </head> <body> <p> <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></p> </body> </html>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (HtmlImprover.run (src) ) self.assertEqual (expectedResult, result, result)
def testImproved1 (self): src = u"""<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 = u"""<!DOCTYPE html> <HTML> <HEAD> <META HTTP-EQUIV='X-UA-Compatible' CONTENT='IE=edge' /> <META HTTP-EQUIV='CONTENT-TYPE' CONTENT='TEXT/HTML; CHARSET=UTF-8'/> <STYLE type='text/css'> body, div, p, table { font-size:10pt; font-family:Verdana; } img{border:none} </STYLE> </HEAD> <BODY> <P> <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></P> </BODY> </HTML>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (HtmlImprover.run (src) ) self.assertEqual (expectedResult, result, result)
def testImproved2 (self): src = ur"""<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 = ur"""<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)
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)
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 htmlAttrs = parser.htmlAttrs # Create final HTML file tpl = HtmlTemplate(readTextFile(stylepath)) result = tpl.substitute(content=text, userhead=head, userhtmlattrs=htmlAttrs, title=self.page.display_title) result = self._changeContentByEvent(self.page, PostprocessingParams(result), Application.onPostprocessing) return result
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
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
def testImproved2 (self): src = ur"""<H2>Attach links</H2><P>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><P><H2>Images</H2>""" expectedResult = ur"""<!DOCTYPE html> <HTML> <HEAD> <META HTTP-EQUIV='X-UA-Compatible' CONTENT='IE=edge' /> <META HTTP-EQUIV='CONTENT-TYPE' CONTENT='TEXT/HTML; CHARSET=UTF-8'/> <STYLE type='text/css'> body, div, p, table { font-size:10pt; font-family:Verdana; } img{border:none} </STYLE> </HEAD> <BODY> <P> <H2>Attach links</H2></P> <P>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></P> <P> <H2>Images</H2></P> </BODY> </HTML>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (HtmlImprover.run (src) ) self.assertEqual (expectedResult, result)
def testImproved2 (self): src = ur"""<h2>Attach links</h2><p>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><p><h2>Images</h2>""" expectedResult = ur"""<!DOCTYPE html> <html> <head> <meta http-equiv='X-UA-Compatible' content='IE=edge' /> <meta http-equiv='content-type' content='text/html; charset=utf-8'/> <style type='text/css'> body, div, p, table { font-size:10pt; font-family:Verdana; } img{border:none} </style> </head> <body> <p> <h2>Attach links</h2></p> <p>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></p> <p> <h2>Images</h2></p> </body> </html>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (HtmlImprover.run (src) ) self.assertEqual (expectedResult, result)
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
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