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')
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)
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)
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)
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)
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) gfm.TaskListExtension().extendMarkdown(md, md_globals)
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)
def setUp(self): def cb_attrs(parent, li): return {"data-foo": li.text.split("=")[1]} def list_attrs(list, depth): return {"data-tag": list.tag, "data-depth": str(depth)} self.tasklist = gfm.TaskListExtension() self.tasklist_ordered_disabled = gfm.TaskListExtension(ordered=False) self.tasklist_full_disabled = gfm.TaskListExtension(ordered=False, unordered=False) self.tasklist_no_marker = gfm.TaskListExtension(checked=[], unchecked=[]) self.tasklist_patterns = gfm.TaskListExtension(checked=["~o", "[o]"], unchecked=("~", "[ ]")) self.tasklist_max_depth = gfm.TaskListExtension(max_depth=2) self.tasklist_item_attrs = gfm.TaskListExtension( item_attrs={"class": "foo"}) self.tasklist_box_attrs = gfm.TaskListExtension( checkbox_attrs={"name": "foo"}) self.tasklist_box_attrs_cb = gfm.TaskListExtension( checkbox_attrs=cb_attrs) self.tasklist_list_attrs = gfm.TaskListExtension( list_attrs={"class": "somelist"}) self.tasklist_list_attrs_cb = gfm.TaskListExtension( list_attrs=list_attrs)
def setUp(self): def cb_attrs(parent, li): return {'data-foo': li.text.split('=')[1]} def list_attrs(list, depth): return {'data-tag': list.tag, 'data-depth': str(depth)} self.tasklist = gfm.TaskListExtension() self.tasklist_ordered_disabled = gfm.TaskListExtension(ordered=False) self.tasklist_full_disabled = gfm.TaskListExtension(ordered=False, unordered=False) self.tasklist_no_marker = gfm.TaskListExtension(checked=[], unchecked=[]) self.tasklist_patterns = gfm.TaskListExtension(checked=['~o', '[o]'], unchecked=('~', '[ ]')) self.tasklist_max_depth = gfm.TaskListExtension(max_depth=2) self.tasklist_item_attrs = gfm.TaskListExtension( item_attrs={'class': 'foo'}) self.tasklist_box_attrs = gfm.TaskListExtension( checkbox_attrs={'name': 'foo'}) self.tasklist_box_attrs_cb = gfm.TaskListExtension( checkbox_attrs=cb_attrs) self.tasklist_list_attrs = gfm.TaskListExtension( list_attrs={'class': 'somelist'}) self.tasklist_list_attrs_cb = gfm.TaskListExtension( list_attrs=list_attrs)