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

Docs: Add example customizing markdown renderer of ui.markdown() #1338

Open
gadenbuie opened this issue Apr 26, 2024 · 1 comment
Open

Docs: Add example customizing markdown renderer of ui.markdown() #1338

gadenbuie opened this issue Apr 26, 2024 · 1 comment

Comments

@gadenbuie
Copy link
Collaborator

In answering a question on Discord, I came up with the following example that uses commonmark markdown rendering with the attributes plugin enabled.

from shiny.express import ui

from markdown_it import MarkdownIt
from mdit_py_plugins import attrs
md = MarkdownIt().use(attrs.attrs_plugin)

ui.markdown(
    '[shiny](https://shiny.posit.co/py){target="_blank"}',
    render_func=md.render
)

Without the additional customization, the default markdown format of ui.markdown() uses GFM, which doesn't support [link](target){attr="value"} syntax.

@gadenbuie
Copy link
Collaborator Author

We should also document that "gfm" is commonmark with the table, linkify, strikethrough and tasklist plugins enabled (if linkify and tasklist are available).

# Inspired by MyST-Parser's gfm-only option
# https://github.com/executablebooks/MyST-Parser/blob/ce1245b25/myst_parser/main.py#L257-L269
parser = MarkdownIt("commonmark", {"linkify": True})
parser.enable(["table", "linkify", "strikethrough"])
try:
from mdit_py_plugins.tasklists import tasklists_plugin
parser.use(tasklists_plugin) # type: ignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant