예제 #1
0
파일: Comment.py 프로젝트: timmjd/jasy
    def getHtml(self, highlight=True):
        """Returns the comment text converted to HTML"""

        if highlight:

            # lazily generate highlighted version
            if self.__highlightedText is None:

                if Markdown.markdown is None:
                    raise UserError("Markdown is not supported by the system. Documentation comments could converted to HTML.")

                highlightedText = '' # text with both markdown and code highlightiong
                for b in self.__blocks:
                    if b["type"] == "comment":
                        highlightedText += Markdown.markdown(b["processed"])

                    else:
                        highlightedText += "\n" + Markdown.markdown(b["text"], True)

                self.__highlightedText = highlightedText

            return self.__highlightedText

        else:
            
            if self.__processedText is None:
            
                if Markdown.markdown is None:
                    raise UserError("Markdown is not supported by the system. Documentation comments could converted to HTML.")

                processedText = ''
                for b in self.__blocks:

                    if b["type"] == "comment":

                        processedText += Markdown.markdown(b["processed"]) 

                    else:
                        processedText += "\n" + b["text"] + "\n\n"

                # Store original, unstripped text for later Markdown conversion
                self.__processedText = processedText.strip()

            return self.__processedText
예제 #2
0
파일: Doc.py 프로젝트: timmjd/jasy
    def getApi(self):
        field = "api[%s]" % self.id
        apidata = self.project.getCache().read(field, self.getModificationTime())
        
        if Markdown.markdown is None:
            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"] = Markdown.markdown(self.getText())
            
            self.project.getCache().store(field, apidata, self.getModificationTime())

        return apidata
        
예제 #3
0
파일: Comment.py 프로젝트: timmjd/jasy
    def __splitBlocks(self, text):

        """Splits up text and code blocks in comments.
        
        This will try to use Misaka for Markdown parsing if available and will 
        fallback to a simpler implementation in order to allow processing of
        doc parameters and links without Misaka being installed."""

        if Markdown.markdown is None:
            return self.__splitSimple(text)
        
        marked = Markdown.markdown(text, False)

        def unescape(html):
            html = html.replace('&lt;', '<')
            html = html.replace('&gt;', '>')
            html = html.replace('&amp;', '&')
            html = html.replace('&quot;', '"')
            return html.replace('&#39;', "'")

        parts = []

        lineNo = 0
        lines = text.split("\n")
        markedLines = marked.split("\n")

        i = 0
        while i < len(markedLines):

            l = markedLines[i]

            # the original text of the line
            parsed = unescape(stripMarkup.sub("", l))

            # start of a code block, grab all text before it and move it into a block
            if l.startswith('<pre><code>'):

                # everything since the last code block and before this one must be text
                comment = []
                for s in range(lineNo, len(lines)):

                    source = lines[s]
                    if source.strip() == parsed.strip():
                        lineNo = s
                        break

                    comment.append(source)

                parts.append({
                    "type": "comment",
                    "text": "\n".join(comment)
                })

                # Find the end of the code block
                e = i
                while i < len(markedLines):
                    l = markedLines[i]
                    i += 1

                    if l.startswith('</code></pre>'):
                        break

                lineCount = (i - e) - 1

                # add the code block
                parts.append({
                    "type": "code",
                    "text": "\n".join(lines[lineNo:lineNo + lineCount])
                })

                lineNo += lineCount

            else:
                i += 1
            
        # append the rest of the comment as text
        parts.append({
            "type": "comment",
            "text": "\n".join(lines[lineNo:])
        })

        return parts