from panflute import Element, Block, Inline, Null, Str, Doc, convert_text, Para, Plain import re def inlinify(e: Element) -> Element: if len(e.content) == 1 and (isinstance(e.content[0], Para) or isinstance(e.content[0], Plain)): return e.content[0].content def replaceEl(e: Element, r: Element) -> Element: parent = e.parent parent.content[e.index] = r r.parent = parent return r def deleteEl(e: Element): del e.parent.content[e.index] def nullify(e: Element): if isinstance(e, Inline): return Str("") elif isinstance(e, Block): return Null() def import_md(s: str, standalone: bool=True) -> Doc: return convert_text(s, standalone=standalone)