def getHtml(self, highlight=True): """ Returns the comment text converted to HTML. :param highlight: Whether to highlight the code :type highlight: bool """ if not Text.supportsMarkdown: raise UserError( "Markdown is not supported by the system. Documentation comments could converted to HTML." ) if highlight: if self.__highlightedText is None: highlightedText = "" for block in self.__blocks: if block["type"] == "comment": highlightedText += Text.highlightCodeBlocks( Text.markdownToHtml(block["processed"])) else: highlightedText += "\n%s" % Text.highlightCodeBlocks( Text.markdownToHtml(block["text"])) self.__highlightedText = highlightedText return self.__highlightedText else: if self.__processedText is None: processedText = "" for block in self.__blocks: if block["type"] == "comment": processedText += Text.markdownToHtml( block["processed"]) else: processedText += "\n%s\n\n" % block["text"] self.__processedText = processedText.strip() return self.__processedText
def getHtml(self, highlight=True): """ Returns the comment text converted to HTML. :param highlight: Whether to highlight the code :type highlight: bool """ if not Text.supportsMarkdown: raise UserError("Markdown is not supported by the system. Documentation comments could converted to HTML.") if highlight: if self.__highlightedText is None: highlightedText = "" for block in self.__blocks: if block["type"] == "comment": highlightedText += Text.highlightCodeBlocks(Text.markdownToHtml(block["processed"])) else: highlightedText += "\n%s" % Text.highlightCodeBlocks(Text.markdownToHtml(block["text"])) self.__highlightedText = highlightedText return self.__highlightedText else: if self.__processedText is None: processedText = "" for block in self.__blocks: if block["type"] == "comment": processedText += Text.markdownToHtml(block["processed"]) else: processedText += "\n%s\n\n" % block["text"] self.__processedText = processedText.strip() return self.__processedText
def getApi(self): field = "api[%s]" % self.id apidata = self.project.getCache().read(field, self.getModificationTime()) if not Text.supportsMarkdown: raise UserError("Missing Markdown feature to convert package docs into HTML.") if apidata is None: apidata = Data.ApiData(self.id) apidata.main["type"] = "Package" apidata.main["doc"] = Text.highlightCodeBlocks(Text.markdownToHtml(self.getText())) self.project.getCache().store(field, apidata, self.getModificationTime()) return apidata
def getApi(self): field = "api[%s]" % self.id apidata = self.project.getCache().read(field, self.getModificationTime()) if not Text.supportsMarkdown: raise UserError( "Missing Markdown feature to convert package docs into HTML.") if apidata is None: apidata = Data.ApiData(self.id) apidata.main["type"] = "Package" apidata.main["doc"] = Text.highlightCodeBlocks( Text.markdownToHtml(self.getText())) self.project.getCache().store(field, apidata, self.getModificationTime()) return apidata
def test_markdown(self): self.assertEqual(Text.markdownToHtml("*emphased*"), "<p><em>emphased</em></p>\n") self.assertEqual(Text.markdownToHtml("**bold**"), "<p><strong>bold</strong></p>\n") self.assertEqual(Text.markdownToHtml("# Header 1"), "<h1>Header 1</h1>\n") self.assertEqual(Text.markdownToHtml("## Header 2"), "<h2>Header 2</h2>\n") self.assertEqual(Text.markdownToHtml("### Header 3"), "<h3>Header 3</h3>\n") self.assertEqual(Text.markdownToHtml("#### Header 4"), "<h4>Header 4</h4>\n") self.assertEqual(Text.markdownToHtml("##### Header 5"), "<h5>Header 5</h5>\n") self.assertEqual(Text.markdownToHtml("###### Header 6"), "<h6>Header 6</h6>\n") self.assertEqual(Text.markdownToHtml(""" Paragraph 1 Paragraph 2 """), "<p>Paragraph 1</p>\n\n<p>Paragraph 2</p>\n") self.assertEqual(Text.markdownToHtml(""" - Item 1 - Item 2 - Item 3 """), "<ul>\n<li>Item 1</li>\n<li>Item 2</li>\n<li>Item 3</li>\n</ul>\n") self.assertEqual(Text.markdownToHtml(""" 1. Item 1 2. Item 2 3. Item 3 """), "<ol>\n<li>Item 1</li>\n<li>Item 2</li>\n<li>Item 3</li>\n</ol>\n") self.assertEqual(Text.highlightCodeBlocks(Text.markdownToHtml(""" ```js alert("hello"); ``` """)), '''<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span class="nx">alert</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">);</span> </pre></div> </td></tr></table> ''')