Skip to content

Commit 85615c0

Browse files
Merge pull request #137 from EmilyBourne/ebourne-133-equation-rendering
2 parents fa86010 + 6f49f11 commit 85615c0

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

mkdoxy/markdown.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,22 @@ def render(self, f: MdRenderer, indent: str):
224224
f.write("|")
225225
is_first = False
226226
f.write("\n\n")
227+
228+
229+
class MdInlineEquation(Md):
230+
def __init__(self, equation: str):
231+
self.equation = equation
232+
233+
def render(self, f: MdRenderer, indent: str):
234+
if self.equation:
235+
f.write(rf"\({self.equation}\)")
236+
237+
238+
class MdBlockEquation(Md):
239+
def __init__(self, equation: str):
240+
self.equation = equation
241+
242+
def render(self, f: MdRenderer, indent: str):
243+
f.write("\n")
244+
f.write(rf"{indent}\[{self.equation}\]")
245+
f.write("\n")

mkdoxy/xml_parser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
Code,
77
Md,
88
MdBlockQuote,
9+
MdBlockEquation,
910
MdBold,
1011
MdCodeBlock,
1112
MdHeader,
1213
MdImage,
14+
MdInlineEquation,
1315
MdItalic,
1416
MdLink,
1517
MdList,
@@ -277,6 +279,12 @@ def paras(self, p: Element, italic: bool = False) -> [Md]:
277279

278280
elif item.tag == "emphasis":
279281
ret.append(MdItalic(self.paras(item)))
282+
elif item.tag == "formula" and item.text:
283+
equation = item.text.strip("$").strip()
284+
if len(p) == 1 and not item.tail:
285+
ret.append(MdBlockEquation(equation))
286+
else:
287+
ret.append(MdInlineEquation(equation))
280288

281289
if item.tail:
282290
if italic:

0 commit comments

Comments
 (0)