Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dollarmath: Add allow_blank_lines option #46

Merged
merged 11 commits into from
Mar 6, 2023
Prev Previous commit
Next Next commit
Add a feature flag to restore the old behavior
eric-wieser authored Mar 3, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit e74277d97f3ea0913729ba765db7407a5e95e845
9 changes: 7 additions & 2 deletions mdit_py_plugins/dollarmath/index.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ def dollarmath_plugin(
allow_labels: bool = True,
allow_space: bool = True,
allow_digits: bool = True,
allow_blank_lines: bool = False,
double_inline: bool = False,
label_normalizer: Optional[Callable[[str], str]] = None,
renderer: Optional[Callable[[str, Dict[str, Any]], str]] = None,
@@ -30,6 +31,9 @@ def dollarmath_plugin(
:param allow_digits: Parse inline math when there is a digit
before/after the opening/closing ``$``, e.g. ``1$`` or ``$2``.
This is useful when also using currency.
:param allow_blank_lines: Allow blank lines inside ``$$``. Note that blank lines are
not allowed in LaTeX nor executablebooks/markdown-it-dollarmath, but have special
semantics if used within Sphinx `..math` admonitions.
:param double_inline: Search for double-dollar math within inline contexts
:param label_normalizer: Function to normalize the label,
by default replaces whitespace with `-`
@@ -47,7 +51,7 @@ def dollarmath_plugin(
math_inline_dollar(allow_space, allow_digits, double_inline),
)
md.block.ruler.before(
"fence", "math_block", math_block_dollar(allow_labels, label_normalizer)
"fence", "math_block", math_block_dollar(allow_labels, label_normalizer, allow_blank_lines)
)

# TODO the current render rules are really just for testing
@@ -247,6 +251,7 @@ def _math_inline_dollar(state: StateInline, silent: bool) -> bool:
def math_block_dollar(
allow_labels: bool = True,
label_normalizer: Optional[Callable[[str], str]] = None,
allow_blank_lines: bool = False,
) -> Callable[[StateBlock, int, int, bool], bool]:
"""Generate block dollar rule."""

@@ -308,7 +313,7 @@ def _math_block_dollar(
haveEndMarker = True
end = end - 2 - (len(lineText) - len(lineText.strip()))
break
if lineText.strip() == "":
if lineText.strip() == "" and not allow_blank_lines:
break # blank lines are not allowed within $$

# reverse the line and match