Skip to content

Commit

Permalink
fix: renderer="ast" same as render=None (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewdeanmartin authored Jun 9, 2023
1 parent d65a097 commit fc19c49
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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

0 comments on commit fc19c49

Please sign in to comment.