Migrating from markdown2#
Replace markdown2’s Markdown-to-HTML calls and extras with Wenmode presets, configured rules, AST helpers, and renderer options.
markdown2 exposes a compact API and optional extras. Wenmode is more explicit: syntax is selected by presets or rules, and output is controlled by renderers.
Simple rendering#
markdown2’s common API is:
import markdown2
html = markdown2.markdown(text)
Use Wenmode’s high-level renderer:
from wenmode import Wenmode
html = Wenmode().render(text)
If you previously reused a markdown2 converter object, keep a reusable Wenmode instance:
import markdown2
converter = markdown2.Markdown(extras=['tables'])
html = converter.convert(text)
from wenmode import Wenmode
from wenmode.presets import github
wen = Wenmode(github)
html = wen.render(text)
Extras mapping#
markdown2 extras vary in scope. Some map directly to Wenmode rules; others need custom plugins or preprocessing.
markdown2 extra |
Wenmode replacement |
|---|---|
|
|
|
default |
|
|
|
|
|
|
|
usually no direct migration; test the exact documents and adjust rule lists if needed |
|
run a typography transform before or after Wenmode, or add a custom renderer transform |
|
|
|
heading helpers plus |
Tables, footnotes, and strikethrough#
For the common “extras for GFM-like documents” setup:
import markdown2
html = markdown2.markdown(text, extras=['tables', 'footnotes', 'strike'])
Use Wenmode’s github preset:
from wenmode import Wenmode
from wenmode.presets import github
html = Wenmode(github).render(text)
Heading IDs#
If you used markdown2’s header ID support, enable heading ID transforms:
import markdown2
html = markdown2.markdown(text, extras=['header-ids'])
from wenmode import Wenmode
from wenmode.headings import HeadingIdTransform
from wenmode.rules import AtxHeading, SetextHeading
wen = Wenmode([
AtxHeading(transforms=[HeadingIdTransform()]),
SetextHeading(transforms=[HeadingIdTransform()]),
])
html = wen.render(text)
For a fuller CommonMark-like dialect with heading IDs, start from
commonmark and replace the heading rules with configured instances.
Raw HTML behavior#
Review raw HTML behavior carefully. Wenmode’s default renderer escapes raw HTML nodes and sanitizes unsafe URLs:
import markdown2
html = markdown2.markdown(text)
from wenmode import Wenmode
html = Wenmode().render(text)
Use passthrough only for trusted content:
from wenmode import HTMLRenderer, Wenmode
html = Wenmode(renderer=HTMLRenderer(escape=False)).render(text)
AST and transformations#
markdown2 is primarily an HTML converter. If you added preprocessing or postprocessing around markdown2, consider moving that logic to Wenmode’s AST:
import markdown2
html = markdown2.markdown(text)
from wenmode import Wenmode
root = Wenmode().parse(text)
payload = root.to_ast()
Use root transforms for document-wide state such as definitions, collected metadata, or generated attributes.
Checklist#
Replace
extraswithgithub, configured rules, or custom plugins.Handle front matter or metadata with
wenmode.plugins.frontmatteror application-specificloadanddumpcallbacks.Rebuild heading IDs and TOC behavior with Wenmode helpers.
Compare HTML output for raw HTML, code blocks, tables, and footnotes.