Package: cmarkgfm
Minimalist Python bindings to GitHub’s fork of cmark.InstallationThis package is published on PyPI ascmarkgfmand can be installed withpiporpipenv:pip install --user cmarkgfm
pipenv install cmarkgfmWheels are provided for macOS, Linux, and Windows for Python 3.6, 3.7, 3.8, 3.9, 3.10 and 3.11.UsageHigh-level usage is really straightforward. To render normal CommonMark
markdown:importcmarkgfmhtml=cmarkgfm.markdown_to_html(markdown_text)To render GitHub-flavored markdown:importcmarkgfmhtml=cmarkgfm.github_flavored_markdown_to_html(markdown_text)Advanced UsageOptionsBoth rendering methodsmarkdown_to_htmlandgithub_flavored_markdown_to_htmlhave
an optionaloptionsargument that can be used to activateoptions of cmark.
For example:importcmarkgfmfromcmarkgfm.cmarkimportOptionsascmarkgfmOptionsoptions=(cmarkgfmOptions.CMARK_OPT_GITHUB_PRE_LANG|cmarkgfmOptions.CMARK_OPT_SMART)html=cmarkgfm.markdown_to_html(markdown_text,options)The options are:OptionEffectCMARK_OPT_UNSAFE (>=0.5.0)Allows rendering unsafe HTML and links.CMARK_OPT_SAFE (<0.5.0)Prevents rendering unsafe HTML and links.CMARK_OPT_SMARTRender curly quotes, en/em-dashes, ellipsesCMARK_OPT_NORMALIZEConsolidate adjacent text nodes.CMARK_OPT_HARDBREAKSRenders line breaks within paragraphs as<br>CMARK_OPT_NOBREAKSRender soft line breaks as spaces.CMARK_OPT_SOURCEPOSAddsdata-sourceposto HTML tags indicating
the corresponding line/col ranges in the inputCMARK_OPT_FOOTNOTESParse footnotes.CMARK_OPT_VALIDATE_UTF8Validate UTF-8 in the input before parsing,
replacing illegal sequenceswith the replacement
character U+FFFD.CMARK_OPT_GITHUB_PRE_LANGUse GitHub-style  tags for code blocks.CMARK_OPT_LIBERAL_HTML_TAGBe liberal in interpreting inline HTML tags.CMARK_OPT_STRIKETHROUGH_DOUBLE_TILDEOnly parse strikethroughs if surrounded by exactly
2 tildes. Gives some compatibility with redcarpet.CMARK_OPT_TABLE_PREFER_STYLE_ATTRIBUTESUse style attributes to align table cells instead
of align attributes.Unsafe renderingSince version 0.5.0, the default behavior is safe. In earlier versions, the default behavior is unsafe, as described below. To render potentially unsafe HTML since 0.5.0 pass theCMARK_OPT_UNSAFEoption.CommonMark can render potentially unsafe HTML, including raw HTML, raw Javascript, and potentially unsafe links (including links that run scripts). Althoughgithub_flavored_markdown_to_htmlprevents some raw HTML tags (includingscript) from being rendered, it does not block unsafe URLs in links.Therefore it is recommend to call the rendering method with the SAFE option turned on. The safe option does not render raw HTML or potentially dangerous URLs. (Raw HTML is replaced by a placeholder comment; potentially dangerous URLs are replaced by empty strings.) Dangerous URLs are those that begin withjavascript:,vbscript:,file:, ordata:(except forimage/png,image/gif,image/jpeg, orimage/webpmime types) To do this, use:# cmarkgfm<0.5.0importcmarkgfmfromcmarkgfm.cmarkimportOptionsascmarkgfmOptionshtml=cmarkgfm.markdown_to_html(markdown_text,options=cmarkgfmOptions.CMARK_OPT_SAFE)# orhtml=cmarkgfm.github_flavored_markdown_to_html(markdown_text,options=cmarkgfmOptions.CMARK_OPT_SAFE)If you trust the markdown text to not include any unsafe tags and links, then you may skip this.ContributingPull requests are welcome. :)LicenseThis project is under the MIT License. It includes components under differing
copyright under thethird_partydirectory in this source tree.