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 buddylindsey / dj-blog / tests / test_models.py View on Github external
def test_published_body(self):
        article = mommy.make('djblog.Article', body='hello')

        self.mock.StubOutWithMock(Markdown, 'render')
        Markdown.render('hello').AndReturn('converted text')

        self.mock.ReplayAll()
        a = article.published_body()
        self.mock.VerifyAll()

        self.assertEqual(a, 'converted text')
github pluohust / GitNote / GitNote.py View on Github external
if self.saveStatus or self.createStatus:
            self.saveNote(True)
        itemCount = item.text()
        filename = (itemCount.split("\n"))[0]
        self.pushButton_save.setEnabled(True)
        self.viewfileName = os.path.join(self.listfileDir, filename)
        if self.viewfileName[-3:] != ".md":
            self.viewfileName = self.viewfileName + ".md"
        self.lineEdit_title.setText(filename)
        tmpf = open(self.viewfileName, "r", encoding='UTF-8')
        self.viewTexts = tmpf.read()
        tmpf.close()
        self.showTextDir = self.listfileDir
        #self.textEdit_show.setText(markdown2.markdown(self.showRealPictures(self.viewTexts)))
        #self.textEdit_show.setHtml(markdown2.markdown(self.showRealPictures(self.viewTexts)))
        markdown = mistune.Markdown()
        markdownTxt = markdown(self.showRealPictures(self.viewTexts))
        markdownTxt = markdownTxt.replace("\n<", "$&$&$&").strip()
        markdownTxt = markdownTxt.replace("\n", r"<br>")
        markdownTxt = markdownTxt.replace("$&amp;$&amp;$&amp;", "\n&lt;")
        if self.interfacedata['theme'] == 'black':
            markdownTxt = markdownTxt.replace("<code>", r'<code style="color:rgb(0,215,215)">')
        else:
            markdownTxt = markdownTxt.replace("<code>", r'<code style="color:rgb(0,0,255)">')
        self.textEdit_show.setHtml(markdownTxt)
        self.textEdit_show.moveCursor(QTextCursor.Start)
    </code></code></code></code>
github lektor / lektor-archive / lektor / types / formats.py View on Github external
def make_markdown(env):
    cfg = MarkdownConfig()
    env.plugin_controller.emit('markdown-config', config=cfg)
    renderer = cfg.make_renderer()
    return mistune.Markdown(renderer, **cfg.options)
github Hammerspoon / hammerspoon / scripts / docs / bin / build_docs.py View on Github external
"""Pre-render GitHub-flavoured Markdown, and syntax-highlight code"""
    import mistune
    from pygments import highlight
    from pygments.lexers import get_lexer_by_name
    from pygments.formatters import html

    class HighlightRenderer(mistune.Renderer):
        def block_code(self, code, lang):
            if not lang:
                return '\n<pre><code>%s</code></pre>\n' % \
                    mistune.escape(code)
            lexer = get_lexer_by_name(lang, stripall=True)
            formatter = html.HtmlFormatter()
            return highlight(code, lexer, formatter)

    md = mistune.Markdown(renderer=HighlightRenderer())

    for i in xrange(0, len(data)):
        module = data[i]
        module["desc_gfm"] = md(module["desc"])
        module["doc_gfm"] = md(module["doc"])
        for item_type in TYPE_NAMES:
            items = module[item_type]
            for j in xrange(0, len(items)):
                item = items[j]
                item["def_gfm"] = strip_paragraph(md(item["def"]))
                item["doc_gfm"] = md(item["doc"])
                items[j] = item
        # Now do the same for the deprecated 'items' list
        for j in xrange(0, len(module["items"])):
            item = module["items"][j]
            item["def_gfm"] = strip_paragraph(md(item["def"]))
github uwekamper / yeahletsdothat / src / campaigns / templatetags / campaigns_extras.py View on Github external
# which video to play?
        video_id = m.group(2)

        # call the supplied render_func to make the HTML
        return render_func(video_id, width, height)

    def output_vimeo_link(self, m):
        return self.create_embedded_video(m, self.renderer.vimeo_link)

    def output_youtube_link(self, m):
        return self.create_embedded_video(m, self.renderer.youtube_link)


renderer = MyRenderer()
inline=MyInlineLexer(renderer)
markdown_render = mistune.Markdown(renderer, inline=inline)


@register.filter(name='markdown', is_safe=True)
def markdown(value):
    try:
        return mark_safe(markdown_render(value))
    except TypeError:
        # TypeError is raised when the text value is e.g. None object.
        return ''


@register.filter(name='markdownexcerpt', is_safe=True)
def markdown_excerpt(value):
    text = striptags(markdown_render(value))
    return mark_safe(truncatewords(text, 20))
github yaqwsx / PcbDraw / pcbdraw / populate.py View on Github external
def parse_content(renderer, content):
    lexer = PcbDrawInlineLexer(renderer)
    processor = mistune.Markdown(renderer=renderer, inline=lexer)
    processor(content)
    return renderer.output()
github crossbario / crossbar / docs-old / markdown.py View on Github external
def __init__(self, docroot, extensions = ['.md'], debug = False):
      rend = DocPageRenderer(self, debug)
      inline = MyInlineLexer(rend)
      self._renderer = mistune.Markdown(renderer = rend, inline = inline)
      self._pages = {}
      self.debug = debug

      total = 0
      errors = 0

      for dirpath, dirnames, filenames in os.walk(docroot):
         for f in filenames:
            base, ext = os.path.splitext(f)
            if ext in extensions:
               total += 1
               fp = os.path.join(dirpath, f)
               with open(fp, 'r') as fd:
                  source = fd.read()
                  try:
                     if self.debug:
github epochblue / nanogen / nanogen / renderer.py View on Github external
import mistune
from mistune_contrib import highlight


class NanogenRenderer(highlight.HighlightMixin, mistune.Renderer):
    pass

markdown = mistune.Markdown(renderer=NanogenRenderer(inlinestyles=False, linenos=False))
github bigsinger / CustomContextMenu / bin / plug / tools / md / mdconverter.py View on Github external
css_text = None
    md_text = None

    with codecs.open(css_filename, mode='r', encoding='utf-8') as f:
        css_text = '<style type="text/css">\n' + f.read() + "\n</style>\n"

    with codecs.open(md_filename, mode='r', encoding='utf-8') as f:
        md_text = f.read()

    # 两种方法转换,推荐mistune
    if False:
        html_text = md2html_by_markdown2(md_text)
    else:
        global CODE_LANG
        CODE_LANG = 'java'
        markdown = mistune.Markdown(renderer=HighlightRenderer())
        html_text = markdown(md_text)

    if is_convert_html:
        # save to html file
        #在windows下encoding需要指定为gbk,不能指定为utf-8否则会出现乱码
        with codecs.open(html_filename, 'w', encoding='gbk', errors='xmlcharrefreplace') as f:
            f.write(css_text + html_text)
        if os.path.exists(html_filename):
            os.popen(html_filename)
    else:
        # save to pdf file
        HTML(string=html_text).write_pdf(pdf_filename, stylesheets=[css_filename])
        if os.path.exists(pdf_filename):
            os.popen(pdf_filename)
github thorstenb / odpdown / odpgenerator.py View on Github external
help='Input ODP template file')
    parser.add_argument('output_odp',
                        type=argparse.FileType('w'),
                        help='Output ODP file')
    parser.add_argument('-p', '--page', default=-1, type=int,
                        help='Append markdown after given page. Negative numbers count from the'
                        ' end of the slide stack')
    args = parser.parse_args()

    markdown = args.input_md
    odf_in = args.template_odp
    odf_out = args.output_odp
    presentation = odf_get_document(odf_in)

    odf_renderer = ODFRenderer(presentation)
    mkdown = mistune.Markdown(renderer=odf_renderer)

    doc_elems = presentation.get_body()
    if args.page &lt; 0:
        args.page = len(doc_elems.get_children()) + args.page

    for index, page in enumerate(mkdown.render(markdown.read()).get()):
        doc_elems.insert(page, position=args.page + index)

        presentation.save(target=odf_out, pretty=False)