Skip to content

Commit

Permalink
馃摎 DOCS: Add section about markdown renderer (#227)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Sewell <chrisj_sewell@hotmail.com>
  • Loading branch information
holamgadol and chrisjsewell committed Feb 22, 2023
1 parent c9f6856 commit 032c742
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/using.md
Expand Up @@ -397,3 +397,29 @@ md = MarkdownIt("commonmark")
md.add_render_rule("link_open", render_blank_link)
print(md.render("[a]\n\n[a]: b"))
```

### Markdown renderer

You can also render a token stream directly to markdown via the `MDRenderer` class from [`mdformat`](https://github.com/executablebooks/mdformat):

```{code-cell} python
from markdown_it import MarkdownIt
from mdformat.renderer import MDRenderer
md = MarkdownIt("commonmark")
source_markdown = """
Here's some *text*
1. a list
> a *quote*"""
tokens = md.parse(source_markdown)
renderer = MDRenderer()
options = {}
env = {}
output_markdown = renderer.render(tokens, options, env)
```

0 comments on commit 032c742

Please sign in to comment.