How to use the mistune.markdown function in mistune

To help you get started, we’ve selected a few mistune examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lepture / mistune / tests / test_extra.py View on Github external
def test_use_xhtml():
    ret = mistune.markdown('foo\n\n----\n\nbar')
    assert '<hr>' in ret
    ret = mistune.markdown('foo\n\n----\n\nbar', use_xhtml=True)
    assert '<hr>' in ret

    ret = mistune.markdown('foo  \nbar', use_xhtml=True)
    assert '<br>' in ret

    ret = mistune.markdown('![foo](bar "title")', use_xhtml=True)
    assert '<img title="title" alt="foo" src="bar">' in ret
github miyuchina / mistletoe / test / profiler / mistune_profiler.py View on Github external
def run():
    with open('test/profiler/syntax.md', 'r') as fin:
        mistune.markdown(fin.read())
github uccser / cs-field-guide / generator / markdownsection.py View on Github external
def parse_markdown(self, text, strip_tag=''):
        """Render the given text to Markdown
        Optional paramaters:
        - strip_paragraph_tags: Allows removal of given tags
        """
        html = mistune.markdown(text,
                                escape=False,
                                hard_wrap=False,
                                parse_block_html=False,
                                parse_inline_html=False,
                                use_xhtml=False)
        if strip_tag:
            start_tag = '&lt;{}&gt;'.format(strip_tag)
            end_tag = ''.format(strip_tag)
            html = html.replace(start_tag, '')
            html = html.replace(end_tag, '')
        return html
github fabric8-analytics / fabric8-analytics-stack-analysis / tagging_platform / helles / npm_tagger / pytextrank_textrank_scoring.py View on Github external
def markdown_preprocess(markdown_content):
    """Preprocess content written in Markdown language."""
    readme_rendered = mistune.markdown(markdown_content, escape=False)
    soup = BeautifulSoup(readme_rendered, "html.parser")
    # Replace anchors with content where relevant and extract otherwise
    for link in soup.findAll('a'):
        if link.text.startswith('http'):
            link.extract()
        else:
            link.replaceWithChildren()
    # Remove all the images
    for image in soup.findAll('img'):
        image.extract()
    # Remove all the code blocks
    for code_block in soup.findAll('code'):
        code_block.extract()
    return soup.text
github common-workflow-language / common-workflow-language / reference / cwltool / avro_ld / makedoc.py View on Github external
if f["type"] == "doc":
            f["doc"] = number_headings(self.toc, f["doc"])

        if "extends" in f:
            doc += "\n\nExtends [%s](#%s)" % (f["extends"], to_id(f["extends"]))
        if f["name"] in self.subs:
            doc += "\n\nExtended by"
            doc += ", ".join([" [%s](#%s)" % (s, to_id(s)) for s in self.subs[f["name"]]])

        if f["name"] in self.uses:
            doc += "\n\nReferenced by"
            doc += ", ".join([" [%s.%s](#%s)" % (s[0], s[1], to_id(s[0])) for s in self.uses[f["name"]]])
        doc = doc + "\n\n" + f["doc"]

        doc = mistune.markdown(doc, renderer=MyRenderer())

        if f["type"] == "record":
            doc += "<h3>Fields</h3>"
            doc += """"""
            doc += ""
            for i in f["fields"]:
                doc += ""
                tp = i["type"]
                if isinstance(tp, list) and tp[0] == "null":
                    opt = False
                    tp = tp[1:]
                else:
                    opt = True
                doc += "" % (i["name"], typefmt(tp), opt, mistune.markdown(i["doc"]))
                doc += ""
            doc += """<table class="table table-striped"><tbody><tr><th>field</th><th>type</th><th>required</th><th>description</th></tr><tr><td><code>%s</code></td><td>%s</td><td>%s</td><td>%s</td></tr></tbody></table>"""
github nikolak / django_reddit / reddit / models.py View on Github external
def create(cls, author, raw_comment, parent):
        """
        Create a new comment instance. If the parent is submisison
        update comment_count field and save it.
        If parent is comment post it as child comment
        :param author: RedditUser instance
        :type author: RedditUser
        :param raw_comment: Raw comment text
        :type raw_comment: str
        :param parent: Comment or Submission that this comment is child of
        :type parent: Comment | Submission
        :return: New Comment instance
        :rtype: Comment
        """

        html_comment = mistune.markdown(raw_comment)
        # todo: any exceptions possible?
        comment = cls(author=author,
                      author_name=author.user.username,
                      raw_comment=raw_comment,
                      html_comment=html_comment)

        if isinstance(parent, Submission):
            submission = parent
            comment.submission = submission
        elif isinstance(parent, Comment):
            submission = parent.submission
            comment.submission = submission
            comment.parent = parent
        else:
            return
        submission.comment_count += 1
github PacktPublishing / Python-Automation-Cookbook / Chapter09 / search_opportunities.py View on Github external
Set the list in the adequate format for the template
    '''
    # Compose the list of articles
    ARTICLE_TEMPLATE = '* **{title}** {summary}: {link}'
    article_list = [ARTICLE_TEMPLATE.format(title=title, summary=summary,
                                            link=link)
                    for title, summary, link in articles]

    data = {
        'article_list': '\n'.join(article_list),
        'keywords': ', '.join(keywords),
        'feed_list': ', '.join(feed_list),
    }
    text = EMAIL_TEMPLATE.format(**data)

    html_content = mistune.markdown(text)
    html = jinja2.Template(EMAIL_STYLING).render(content=html_content)

    return text, html
github nouhadziri / THRED / thred / corpora / reddit / reddit_parser.py View on Github external
def normalize_post_text(text, charmap=None):
    # footer
    # normalized = re.sub(r'(.+)\n---\n.+', r'\1', text, flags=re.DOTALL)

    # quotes
    normalized = re.sub(r'^&gt;.+\n?.+\n\n', '', text, flags=re.M)

    # derived from https://stackoverflow.com/a/761847
    # stripping markdown syntax
    html = mistune.markdown(normalized)
    normalized = ''.join(BeautifulSoup(html, "html5lib").findAll(text=True)).strip()

    # whitespace html entity
    normalized = re.sub(r'&nbsp;', ' ', normalized)

    # ^() syntax
    normalized = re.sub(r'\^\(([^\^]+)\)', r'\1', normalized)
    normalized = re.sub(r'(^|\s|\w+|[/,|])\^(\s|\w+|[/,|])', r'\1\2', normalized)

    normalized = re.sub(r'[\u2018\u2019]', "'", normalized.replace("\u2605", "*"))
    normalized = re.sub(r'[\u201C\u201D]', '"', normalized)

    # consecutive whitespaces
    normalized = re.sub(r'\s+', ' ', normalized)

    # users and subreddit mentions