Skip to content

Commit

Permalink
fix: do not use excessive memory when rendering markdown (#382)
Browse files Browse the repository at this point in the history
Due to legacy reasons we enabled the emoji plugin from pymdown.
Every time the Markdown object gets created, it will load the
emoji extension and will deep copy the emoji database.
This is about 150kb of data:
len(str(pymdownx.emoji1_db.emoji))

This is not a lot, but it is unnecessary and can be avoided.
  • Loading branch information
maartenbreddels authored Nov 15, 2023
1 parent a93d8cb commit a991ed8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions solara/components/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any, Dict, List, Union

import ipyvuetify as v
import pymdownx.emoji
import pymdownx.highlight
import pymdownx.superfences

Expand Down Expand Up @@ -183,6 +184,13 @@ def highlight_code(code, name, attrs):
return v.VuetifyTemplate.element(template=_markdown_template(html)).key(hash)


_index = pymdownx.emoji.emojione(None, None)


def _no_deep_copy_emojione(options, md):
return _index


@solara.component
def Markdown(md_text: str, unsafe_solara_execute=False, style: Union[str, Dict, None] = None):
"""Renders markdown text
Expand Down Expand Up @@ -248,6 +256,9 @@ def highlight(src, language, *args, **kwargs):
"tables",
],
extension_configs={
"pymdownx.emoji": {
"emoji_index": _no_deep_copy_emojione,
},
"pymdownx.superfences": {
"custom_fences": [
{
Expand Down

0 comments on commit a991ed8

Please sign in to comment.