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 authored 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
Original file line number Diff line number Diff line change
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.