Python markdown2 模块,Markdown() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用markdown2.Markdown()

项目:9XD    作者:9XD    | 项目源码 | 文件源码
def save(self, commit=True):
        author = self.cleaned_data['author']
        title = self.cleaned_data['title']
        content = self.cleaned_data['content']
        markdown = Markdown()
        html = markdown.convert(content)
        post = Post(author=author, title=title, content=content, html=html)
        post.save()

        tags_text = self.cleaned_data['tags']
        tag_names = split_tags(tags_text)
        for tag_name in tag_names:
            tag_name.strip()
            if 0 < len(tag_name) < 16:
                tag = self.create_and_get(tag_name)
                post.tags.add(tag)

        return self.instance
项目:pyusernotify    作者:ericjaystevens    | 项目源码 | 文件源码
def getMessage(self):
        msgAsMarkdown = ""
        subject = ""
        # for each line in file
        # set the first line to message 
        # put the rest into a long string
        f = open(self.templatePath,"r")
        lines = f.readlines()

        firstLineOfMessage = 0


        for line in lines:
            firstLineOfMessage = firstLineOfMessage + 1
            if line == '\n':
                break

        for i in range(firstLineOfMessage,len(lines)):
            msgAsMarkdown = msgAsMarkdown + lines[i]

        markdowner = Markdown()
        message = markdowner.convert(msgAsMarkdown)
        f.close()
        return message
项目:9XD    作者:9XD    | 项目源码 | 文件源码
def convert_markdown(request):
    markdown = Markdown()
    converted_string = markdown.convert(request.POST['text'])
    return HttpResponse(converted_string)
项目:smurf    作者:oxalorg    | 项目源码 | 文件源码
def get_markdown():
    """
    Find and set a valid markdown parser
    Checks for one of these parsers:
        - pandoc
        - markdown2
    """
    markdown = None
    if shutil.which('pandoc'):
        markdown = lambda x: subprocess.run(
            ["pandoc", "-f", "markdown", "-t", "html"],
            input=x.encode("utf-8"),
            stdout=subprocess.PIPE).stdout.decode("utf-8")
    else:
        try:
            import markdown2
            _md_extras = [
                "code-friendly",
                "fenced-code-blocks",
                "footnotes",
                "header-ids",
            ]
            markdown = markdown2.Markdown(extras=_md_extras).convert
        except ImportError:
            pass

    if markdown is None:
        print("No markdown parser found. Will serve as plain text.")
    return markdown