Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderer="ast" same as render=None #351

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/upgrade.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ When customizing renderers, these methods' parameters are changed:
AstRenderer
~~~~~~~~~~~

There is no ``AstRenderer`` in v3, just pass ``None`` to ``create_markdown``::
There is no ``AstRenderer`` in v3, just pass ``None`` or ``'ast'`` to ``create_markdown``::

import mistune

md = mistune.create_markdown(renderer=None)
md = mistune.create_markdown(renderer='ast') # or render=None
md('...markdown text...')

Plugins
Expand Down
8 changes: 7 additions & 1 deletion src/mistune/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def create_markdown(escape: bool=True, hard_wrap: bool=False, renderer='html', p
# re-use markdown function
markdown('.... your text ...')
"""
if renderer == 'html':
if renderer == 'ast':
# explicit and more similar to 2.x's API
renderer = None
elif renderer == 'html':
renderer = HTMLRenderer(escape=escape)

inline = InlineParser(hard_wrap=hard_wrap)
Expand All @@ -53,6 +56,9 @@ def create_markdown(escape: bool=True, hard_wrap: bool=False, renderer='html', p


def markdown(text, escape=True, renderer='html', plugins=None) -> str:
if renderer == 'ast':
# explicit and more similar to 2.x's API
renderer = None
key = (escape, renderer, plugins)
if key in __cached_parsers:
return __cached_parsers[key](text)
Expand Down