add load_resources to markdown

This commit is contained in:
Fabio Pliger
2024-01-31 17:56:41 -06:00
parent be65cf37ce
commit f37048f09e
3 changed files with 15 additions and 20 deletions

View File

@@ -1,7 +1,7 @@
"""Markdown module to generate web/HTML components from Markdown code"""
from pyscript import document, window
from pyweb.ui.elements import TextElementBase
from pyweb import pydom
from pyweb.ui.elements import TextElementBase, script
class markdown(TextElementBase):
"""Markdown component to render HTML from Markdown code"""
@@ -10,5 +10,17 @@ class markdown(TextElementBase):
def __init__(self, content, style=None, **kwargs):
# TODO: We should sanitize the content!!!!!
html = window.marked.parse(content)
super().__init__(html, style=style, **kwargs)
# TODO: DON'T KNOW WHY BUT THIS DOESN'T WORK
def load_resources(parent=None):
if parent is None:
parent = pydom.body
parent.append(
script(src="https://cdn.jsdelivr.net/npm/marked@11.1.1/lib/marked.umd.min.js"),
)
# load_resources()