Take the markdown source, convert to HTML/XML and save in the file called fileName. If the fileName does not end with ".xml" extension, then add it. Answer the (new) fileName. >>> import os >>> from pagebot.contexts.htmlcontext.htmlcontext import HtmlContext
(self, fileName, mdText, mdExtensions=None)
| 689 | self.popStyle() |
| 690 | |
| 691 | def markDown2XmlFile(self, fileName, mdText, mdExtensions=None): |
| 692 | """Take the markdown source, convert to HTML/XML and save in the file |
| 693 | called fileName. If the fileName does not end with ".xml" extension, |
| 694 | then add it. Answer the (new) fileName. |
| 695 | |
| 696 | >>> import os |
| 697 | >>> from pagebot.contexts.htmlcontext.htmlcontext import HtmlContext |
| 698 | >>> md = '''## Subtitle at start\\n\\n~~~\\npage = page.next\\n~~~\\n\\n# Title\\n\\n##Subtitle\\n\\nPlain text''' |
| 699 | >>> context = HtmlContext() |
| 700 | >>> t = Typesetter(context) |
| 701 | >>> fileName = t.markDown2XmlFile('/tmp/PageBot_Typesetter_test.xml', md) |
| 702 | >>> #os.remove(fileName) |
| 703 | """ |
| 704 | if mdExtensions is None: |
| 705 | mdExtensions = self.MARKDOWN_EXTENSIONS |
| 706 | |
| 707 | # Otherwise MarkDown will auto-convert. |
| 708 | if not self.tabs2Space: |
| 709 | # Keep the tabs, as they get replaced into spaced by MarkDown. |
| 710 | mdText = mdText.replace('\t', '<tab/>') |
| 711 | |
| 712 | xmlBody = markdown.markdown(mdText, extensions=mdExtensions) |
| 713 | xml = u'<?xml version="1.0" encoding="utf-8"?>\n<document>%s</document>' % xmlBody |
| 714 | |
| 715 | if self.return2Space: |
| 716 | for c1, c2 in (('\r', ' '), ('\n', ' '), (' ', ' ')): |
| 717 | # Replace all returns by tabs. Paragraphs should be made with <p> and <br/>. |
| 718 | xml = xml.replace(c1, c2) |
| 719 | xml += '\r' |
| 720 | |
| 721 | if not fileName.endswith('.xml'): |
| 722 | # Make sure file name has xml extension. |
| 723 | fileName = fileName + '.xml' |
| 724 | |
| 725 | # Save the XML as unicode. |
| 726 | f = codecs.open(fileName, mode="w", encoding="utf-8") |
| 727 | f.write(xml) |
| 728 | f.close() |
| 729 | return fileName |
| 730 | |
| 731 | def typesetMarkdown(self, mdText, mdExtensions=None, e=None, xPath=None): |
| 732 | tmpPath = '/tmp/PageBot_Typesetter.xml' |
no test coverage detected