Files
pyscript/pyscriptjs/src/plugins/python/py_markdown.py
Madhur Tandon c8f9f16791 synclink integration (#1258)
synclink integration + fixes for `py-repl` related tests and `display` tests
2023-03-27 20:56:31 +05:30

35 lines
942 B
Python

import html
from textwrap import dedent
from js import console
from markdown import markdown
from pyscript import Plugin
console.warn(
"WARNING: This plugin is still in a very experimental phase and will likely change"
" and potentially break in the future releases. Use it with caution."
)
class MyPlugin(Plugin):
def configure(self, config):
console.log(f"configuration received: {config}")
def afterStartup(self, interpreter):
console.log("interpreter received:", interpreter)
plugin = MyPlugin("py-markdown")
@plugin.register_custom_element("py-md")
class PyMarkdown:
def __init__(self, element):
self.element = element
def connect(self):
unescaped_content = html.unescape(self.element.originalInnerHTML)
original = dedent(unescaped_content)
inner = markdown(original, extensions=["markdown.extensions.fenced_code"])
self.element.innerHTML = inner