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

Commit

Permalink
fix(parsing): Make sure that equation blocks use title_plaintext, add…
Browse files Browse the repository at this point in the history
…ed test to make sure underscore parsing was handled properly
  • Loading branch information
Cobertos committed Mar 28, 2021
1 parent ba09960 commit fcadb2b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion md2notion/NotionPyRenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def render_block_equation(self, token):
def blockFunc(blockStr):
return {
'type': EquationBlock,
'title': blockStr.replace('\\', '\\\\')
'title_plaintext': blockStr.replace('\\', '\\\\')
}
return self.renderMultipleToStringAndCombine(token.children, blockFunc)

Expand Down
25 changes: 22 additions & 3 deletions tests/test_NotionPyRenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ def test_latex_inline():
assert output[1]['type'] == notion.block.TextBlock
assert output[1]['title'] == r'Text before $$f(x) = \sigma(w \cdot x + b)$$ Text after'

def test_latex_inline_with_underscores():
'''it should render a latex block with underscores in it properly'''
output = mistletoe.markdown(r'Text before $X^T=(X_1, X_2, \ldots, X_p)$ Text after', addLatexExtension(NotionPyRenderer))

assert len(output) == 1
output = output[0]
assert output is not None
assert output['type'] == notion.block.TextBlock
assert output['title'] == r'Text before $$X^T=(X_1, X_2, \ldots, X_p)$$ Text after'

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

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

def test_cli_latex_extension():
pass
def test_latex_block_with_underscores():
'''it should render a latex block with underscores in it properly'''
output = mistletoe.markdown(r"""
$$
\hat{Y} = \hat{\beta}_0 + \sum_{j=1}^p X_j \hat{\beta}_j
$$""", addLatexExtension(NotionPyRenderer))

assert len(output) == 1
output = output[0]
assert output is not None
assert output['type'] == notion.block.EquationBlock
assert output['title_plaintext'] == '\\\\hat{Y} = \\\\hat{\\\\beta}_0 + \\\\sum_{j=1}^p X_j \\\\hat{\\\\beta}_j\n'

def test_escapeSequence():
'''it should render out an escape sequence'''
Expand Down

0 comments on commit fcadb2b

Please sign in to comment.