示例#1
0
def _init_flavored_markdown():
    import markdown.extensions.codehilite
    import markdown.extensions.fenced_code
    import markdown.extensions.tables
    import markdown.extensions.footnotes
    import markdown.extensions.toc
    import markdown.extensions.smart_strong
    import gfm
    from prologin.utils.markdown.nofollow import NofollowExtension
    ext = [
        markdown.extensions.fenced_code.FencedCodeExtension(),
        markdown.extensions.tables.TableExtension(),
        markdown.extensions.footnotes.FootnoteExtension(),
        markdown.extensions.smart_strong.SmartEmphasisExtension(),
        markdown.extensions.codehilite.CodeHiliteExtension(
            linenums=True, css_class="codehilite"),
        markdown.extensions.toc.TocExtension(
            slugify=lambda s, _: slugify('bdy-' + s),
            permalink=True,
            baselevel=1),
        gfm.AutolinkExtension(),
        gfm.AutomailExtension(),
        gfm.SemiSaneListExtension(),
        gfm.SpacedLinkExtension(),
        gfm.StrikethroughExtension(),
        gfm.TaskListExtension(
            checked=('[x]', '✅', '✓', '✔'),
            unchecked=('[ ]', '✗', '✘'),
            item_attrs={'class': 'task-list-item'},
            checkbox_attrs={'class': 'task-list-item-checkbox'}),
        NofollowExtension(),
    ]
    return markdown_lib.Markdown(extensions=ext, output_format='html5')
示例#2
0
def convert(md):
    import urllib.parse  # Python 3 only

    def my_slugify(value, sep):
        return urllib.parse.quote_plus(value.replace(' ', sep))

    extensions = [
        markdown.extensions.codehilite.CodeHiliteExtension(
            css_class='highlight',
            linenums=False,
            guess_lang=False,
        ),
        markdown.extensions.extra.ExtraExtension(),
        markdown.extensions.toc.TocExtension(
            toc_depth='2-6',  # h1 not included
            permalink=True,
            slugify=my_slugify,
            title='Table of Contents',
        ),
        markdown.extensions.nl2br.Nl2BrExtension(),
        markdown.extensions.admonition.AdmonitionExtension(),
        markdown_link_attr_modifier.LinkAttrModifierExtension(
            new_tab='on',
            no_referrer='external_only',
            auto_title='on',
        ),
        gfm.StrikethroughExtension(),
        gfm.TaskListExtension(list_attrs={'class': 'task-list'},
                              item_attrs={'class': 'task-list-item'}),
    ]
    return markdown.markdown(md, extensions=extensions)
示例#3
0
    def extendMarkdown(self, md, md_globals):
        # Built-in extensions
        gfmFencedCodeExtension().extendMarkdown(md)
        #FencedCodeExtension().extendMarkdown(md)
        #FencedCodeExtension().extendMarkdown(md, md_globals)
        #SmartEmphasisExtension().extendMarkdown(md, md_globals)
        #TableExtension().extendMarkdown(md, md_globals)
        TableExtension().extendMarkdown(md)

        # Custom extensions
        gfm.AutolinkExtension().extendMarkdown(md, md_globals)
        gfm.AutomailExtension().extendMarkdown(md, md_globals)
        # gfm.HiddenHiliteExtension([
        #     ('guess_lang', 'False'),
        #     ('css_class', 'highlight')
        # ]).extendMarkdown(md, md_globals)
        # print(md_globals)
        # print(self.config)
        # print(dir(md))
        # raise KeyboardInterrupt()
        #print(self.config)
        #gfm.HiddenHiliteExtension().extendMarkdown(md, md_globals)
        gfm.HiddenHiliteExtension().extendMarkdown(md, self.config)
        gfm.SemiSaneListExtension().extendMarkdown(md, md_globals)
        gfm.SpacedLinkExtension().extendMarkdown(md, md_globals)
        gfm.StrikethroughExtension().extendMarkdown(md, md_globals)
        gfm.TaskListExtension().extendMarkdown(md, md_globals)
示例#4
0
    def extendMarkdown(self, md):
        # Built-in extensions
        TableExtension().extendMarkdown(md)

        # Custom extensions
        gfm.AutolinkExtension().extendMarkdown(md)
        gfm.AutomailExtension().extendMarkdown(md)
        gfm.SemiSaneListExtension().extendMarkdown(md)
        gfm.StandaloneFencedCodeExtension().extendMarkdown(md)
        gfm.StrikethroughExtension().extendMarkdown(md)
        gfm.TaskListExtension().extendMarkdown(md)
示例#5
0
    def extendMarkdown(self, md, md_globals):
        # Built-in extensions
        FencedCodeExtension().extendMarkdown(md)
        TableExtension().extendMarkdown(md)

        # Custom extensions
        gfm.AutolinkExtension().extendMarkdown(md, md_globals)
        gfm.AutomailExtension().extendMarkdown(md, md_globals)

        gfm.HiddenHiliteExtension().extendMarkdown(md, self.config)
        gfm.SemiSaneListExtension().extendMarkdown(md, md_globals)
        gfm.SpacedLinkExtension().extendMarkdown(md, md_globals)
        gfm.StrikethroughExtension().extendMarkdown(md, md_globals)
        gfm.TaskListExtension().extendMarkdown(md, md_globals)
示例#6
0
    def extendMarkdown(self, md, md_globals):
        # Built-in extensions
        FencedCodeExtension().extendMarkdown(md, md_globals)
        SmartEmphasisExtension().extendMarkdown(md, md_globals)
        TableExtension().extendMarkdown(md, md_globals)

        # Custom extensions
        gfm.AutolinkExtension().extendMarkdown(md, md_globals)
        gfm.AutomailExtension().extendMarkdown(md, md_globals)
        gfm.HiddenHiliteExtension([('guess_lang', 'False'),
                                   ('css_class', 'highlight')
                                   ]).extendMarkdown(md, md_globals)
        gfm.SemiSaneListExtension().extendMarkdown(md, md_globals)
        gfm.SpacedLinkExtension().extendMarkdown(md, md_globals)
        gfm.StrikethroughExtension().extendMarkdown(md, md_globals)
示例#7
0
    def extendMarkdown(self, md, md_globals):
        # Nl2BrExtension().extendMarkdown(md, md_globals)
        FencedCodeExtension().extendMarkdown(md, md_globals)
        SmartEmphasisExtension().extendMarkdown(md, md_globals)
        TableExtension().extendMarkdown(md, md_globals)
        AdmonitionExtension().extendMarkdown(md, md_globals)

        CodeHiliteExtension(use_pygments=True,
                            css_class='roca_css').extendMarkdown(
                                md, md_globals)

        TocExtension(anchorlink=False,
                     permalink=True).extendMarkdown(md, md_globals)

        gfm.AutomailExtension().extendMarkdown(md, md_globals)
        gfm.SemiSaneListExtension().extendMarkdown(md, md_globals)
        gfm.SpacedLinkExtension().extendMarkdown(md, md_globals)
        gfm.StrikethroughExtension().extendMarkdown(md, md_globals)
        gfm.AutolinkExtension().extendMarkdown(md, md_globals)
        gfm.TaskListExtension().extendMarkdown(md, md_globals)

        SubstituteExtension().extendMarkdown(md, md_globals)
示例#8
0
 def setUp(self):
     self.strikethrough = gfm.StrikethroughExtension([])