Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions mkdoxy/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,22 @@ def render(self, f: MdRenderer, indent: str):
f.write("|")
is_first = False
f.write("\n\n")


class MdInlineEquation(Md):
def __init__(self, equation: str):
self.equation = equation

def render(self, f: MdRenderer, indent: str):
if self.equation:
f.write(rf"\({self.equation}\)")


class MdBlockEquation(Md):
def __init__(self, equation: str):
self.equation = equation

def render(self, f: MdRenderer, indent: str):
f.write("\n")
f.write(rf"\[{self.equation}\]")
f.write("\n")
8 changes: 8 additions & 0 deletions mkdoxy/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
Code,
Md,
MdBlockQuote,
MdBlockEquation,
MdBold,
MdCodeBlock,
MdHeader,
MdImage,
MdInlineEquation,
MdItalic,
MdLink,
MdList,
Expand Down Expand Up @@ -277,6 +279,12 @@ def paras(self, p: Element, italic: bool = False) -> [Md]:

elif item.tag == "emphasis":
ret.append(MdItalic(self.paras(item)))
elif item.tag == "formula":
equation = item.text.strip("$ ")
if len(p) == 1 and item.tail is None:
ret.append(MdBlockEquation(equation))
else:
ret.append(MdInlineEquation(equation))

if item.tail:
if italic:
Expand Down