widgetti / reacton

A pure Python port of React for ipywidgets
https://reacton.solara.dev/
MIT License
289 stars 19 forks source link

Markdown example does not work with myst_parser>=0.18 #3

Closed Alexboiboi closed 1 year ago

Alexboiboi commented 1 year ago

The example from https://github.com/widgetti/reacton#markdown-component-example does not work with myst_parser>=0.18 since the to_html function has been removed from the python api (see https://github.com/executablebooks/MyST-Parser/blob/28725fceb8e1e117cb247b06a267f82c501ce527/CHANGELOG.md#breaking-changes)

One solution:

@reacton.component
def Markdown(md: str):
    from markdown_it.renderer import RendererHTML
    from myst_parser.config.main import MdParserConfig
    from myst_parser.parsers.mdit import create_md_parser
    md_parser = create_md_parser(MdParserConfig(), RendererHTML)
    html = md_parser.render(md)
    return w.HTML(value=html)

BR, Alex

maartenbreddels commented 1 year ago

(FYI, sorry for the late reply, just noticed I didn't get GH notifications from the repo)

I just fixed this in https://github.com/widgetti/reacton/commit/af8b6e0291985fc2a080717a911f8b0648282071 , and also included a Markdown example at:

Markdown example live with Jupyter lite Markdown component and editor