Skip to content
This repository was archived by the owner on Nov 2, 2023. It is now read-only.

Commit fcadb2b

Browse files
committed
fix(parsing): Make sure that equation blocks use title_plaintext, added test to make sure underscore parsing was handled properly
1 parent ba09960 commit fcadb2b

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

md2notion/NotionPyRenderer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def render_block_equation(self, token):
414414
def blockFunc(blockStr):
415415
return {
416416
'type': EquationBlock,
417-
'title': blockStr.replace('\\', '\\\\')
417+
'title_plaintext': blockStr.replace('\\', '\\\\')
418418
}
419419
return self.renderMultipleToStringAndCombine(token.children, blockFunc)
420420

tests/test_NotionPyRenderer.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ def test_latex_inline():
169169
assert output[1]['type'] == notion.block.TextBlock
170170
assert output[1]['title'] == r'Text before $$f(x) = \sigma(w \cdot x + b)$$ Text after'
171171

172+
def test_latex_inline_with_underscores():
173+
'''it should render a latex block with underscores in it properly'''
174+
output = mistletoe.markdown(r'Text before $X^T=(X_1, X_2, \ldots, X_p)$ Text after', addLatexExtension(NotionPyRenderer))
175+
176+
assert len(output) == 1
177+
output = output[0]
178+
assert output is not None
179+
assert output['type'] == notion.block.TextBlock
180+
assert output['title'] == r'Text before $$X^T=(X_1, X_2, \ldots, X_p)$$ Text after'
172181

173182
def test_latex_block():
174183
output = mistletoe.markdown(r"""
@@ -184,10 +193,20 @@ def test_latex_block():
184193

185194
assert output[2] is not None
186195
assert output[2]['type'] == notion.block.EquationBlock
187-
assert output[2]['title'] == 'f(x) = \\\\sigma(w \\\\cdot x + b)\n'
196+
assert output[2]['title_plaintext'] == 'f(x) = \\\\sigma(w \\\\cdot x + b)\n'
188197

189-
def test_cli_latex_extension():
190-
pass
198+
def test_latex_block_with_underscores():
199+
'''it should render a latex block with underscores in it properly'''
200+
output = mistletoe.markdown(r"""
201+
$$
202+
\hat{Y} = \hat{\beta}_0 + \sum_{j=1}^p X_j \hat{\beta}_j
203+
$$""", addLatexExtension(NotionPyRenderer))
204+
205+
assert len(output) == 1
206+
output = output[0]
207+
assert output is not None
208+
assert output['type'] == notion.block.EquationBlock
209+
assert output['title_plaintext'] == '\\\\hat{Y} = \\\\hat{\\\\beta}_0 + \\\\sum_{j=1}^p X_j \\\\hat{\\\\beta}_j\n'
191210

192211
def test_escapeSequence():
193212
'''it should render out an escape sequence'''

0 commit comments

Comments
 (0)