diff --git a/mdit_py_plugins/texmath/index.py b/mdit_py_plugins/texmath/index.py
index f4fb509..ecf178c 100644
--- a/mdit_py_plugins/texmath/index.py
+++ b/mdit_py_plugins/texmath/index.py
@@ -3,7 +3,6 @@
from markdown_it import MarkdownIt
from markdown_it.common.utils import charCodeAt
-from markdown_it.utils import AttrDict
def texmath_plugin(md: MarkdownIt, delimiters="dollars", macros: Optional[dict] = None):
@@ -152,163 +151,157 @@ def render(tex, displayMode, macros):
# All regexes areg global (g) and sticky (y), see:
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky
-rules = AttrDict(
- {
- "brackets": {
- "inline": [
- {
- "name": "math_inline",
- "rex": re.compile(r"^\\\((.+?)\\\)", re.DOTALL),
- "tmpl": "{0}",
- "tag": "\\(",
- }
- ],
- "block": [
- {
- "name": "math_block_eqno",
- "rex": re.compile(
- r"^\\\[(((?!\\\]|\\\[)[\s\S])+?)\\\]\s*?\(([^)$\r\n]+?)\)", re.M
- ),
- "tmpl": '',
- "tag": "\\[",
- },
- {
- "name": "math_block",
- "rex": re.compile(r"^\\\[([\s\S]+?)\\\]", re.M),
- "tmpl": "\n",
- "tag": "\\[",
- },
- ],
- },
- "gitlab": {
- "inline": [
- {
- "name": "math_inline",
- "rex": re.compile(r"^\$`(.+?)`\$"),
- "tmpl": "{0}",
- "tag": "$`",
- }
- ],
- "block": [
- {
- "name": "math_block_eqno",
- "rex": re.compile(
- r"^`{3}math\s+?([^`]+?)\s+?`{3}\s*?\(([^)$\r\n]+?)\)", re.M
- ),
- "tmpl": '\n', # noqa: E501
- "tag": "```math",
- },
- {
- "name": "math_block",
- "rex": re.compile(r"^`{3}math\s+?([^`]+?)\s+?`{3}", re.M),
- "tmpl": "\n",
- "tag": "```math",
- },
- ],
- },
- "julia": {
- "inline": [
- {
- "name": "math_inline",
- "rex": re.compile(r"^`{2}([^`]+?)`{2}"),
- "tmpl": "{0}",
- "tag": "``",
- },
- {
- "name": "math_inline",
- "rex": re.compile(r"^\$(\S[^$\r\n]*?[^\s\\]{1}?)\$"),
- "tmpl": "{0}",
- "tag": "$",
- "pre": dollar_pre,
- "post": dollar_post,
- },
- {
- "name": "math_single",
- "rex": re.compile(r"^\$([^$\s\\]{1}?)\$"),
- "tmpl": "{0}",
- "tag": "$",
- "pre": dollar_pre,
- "post": dollar_post,
- },
- ],
- "block": [
- {
- "name": "math_block_eqno",
- "rex": re.compile(
- r"^`{3}math\s+?([^`]+?)\s+?`{3}\s*?\(([^)$\r\n]+?)\)", re.M
- ),
- "tmpl": '',
- "tag": "```math",
- },
- {
- "name": "math_block",
- "rex": re.compile(r"^`{3}math\s+?([^`]+?)\s+?`{3}", re.M),
- "tmpl": "",
- "tag": "```math",
- },
- ],
- },
- "kramdown": {
- "inline": [
- {
- "name": "math_inline",
- "rex": re.compile(r"^\${2}([^$\r\n]*?)\${2}"),
- "tmpl": "{0}",
- "tag": "$$",
- }
- ],
- "block": [
- {
- "name": "math_block_eqno",
- "rex": re.compile(
- r"^\${2}([^$]*?)\${2}\s*?\(([^)$\r\n]+?)\)", re.M
- ),
- "tmpl": '',
- "tag": "$$",
- },
- {
- "name": "math_block",
- "rex": re.compile(r"^\${2}([^$]*?)\${2}", re.M),
- "tmpl": "",
- "tag": "$$",
- },
- ],
- },
- "dollars": {
- "inline": [
- {
- "name": "math_inline",
- "rex": re.compile(r"^\$(\S[^$]*?[^\s\\]{1}?)\$"),
- "tmpl": "{0}",
- "tag": "$",
- "pre": dollar_pre,
- "post": dollar_post,
- },
- {
- "name": "math_single",
- "rex": re.compile(r"^\$([^$\s\\]{1}?)\$"),
- "tmpl": "{0}",
- "tag": "$",
- "pre": dollar_pre,
- "post": dollar_post,
- },
- ],
- "block": [
- {
- "name": "math_block_eqno",
- "rex": re.compile(
- r"^\${2}([^$]*?)\${2}\s*?\(([^)$\r\n]+?)\)", re.M
- ),
- "tmpl": '\n', # noqa: E501
- "tag": "$$",
- },
- {
- "name": "math_block",
- "rex": re.compile(r"^\${2}([^$]*?)\${2}", re.M),
- "tmpl": "\n",
- "tag": "$$",
- },
- ],
- },
- }
-)
+rules: dict = {
+ "brackets": {
+ "inline": [
+ {
+ "name": "math_inline",
+ "rex": re.compile(r"^\\\((.+?)\\\)", re.DOTALL),
+ "tmpl": "{0}",
+ "tag": "\\(",
+ }
+ ],
+ "block": [
+ {
+ "name": "math_block_eqno",
+ "rex": re.compile(
+ r"^\\\[(((?!\\\]|\\\[)[\s\S])+?)\\\]\s*?\(([^)$\r\n]+?)\)", re.M
+ ),
+ "tmpl": '',
+ "tag": "\\[",
+ },
+ {
+ "name": "math_block",
+ "rex": re.compile(r"^\\\[([\s\S]+?)\\\]", re.M),
+ "tmpl": "\n",
+ "tag": "\\[",
+ },
+ ],
+ },
+ "gitlab": {
+ "inline": [
+ {
+ "name": "math_inline",
+ "rex": re.compile(r"^\$`(.+?)`\$"),
+ "tmpl": "{0}",
+ "tag": "$`",
+ }
+ ],
+ "block": [
+ {
+ "name": "math_block_eqno",
+ "rex": re.compile(
+ r"^`{3}math\s+?([^`]+?)\s+?`{3}\s*?\(([^)$\r\n]+?)\)", re.M
+ ),
+ "tmpl": '\n', # noqa: E501
+ "tag": "```math",
+ },
+ {
+ "name": "math_block",
+ "rex": re.compile(r"^`{3}math\s+?([^`]+?)\s+?`{3}", re.M),
+ "tmpl": "\n",
+ "tag": "```math",
+ },
+ ],
+ },
+ "julia": {
+ "inline": [
+ {
+ "name": "math_inline",
+ "rex": re.compile(r"^`{2}([^`]+?)`{2}"),
+ "tmpl": "{0}",
+ "tag": "``",
+ },
+ {
+ "name": "math_inline",
+ "rex": re.compile(r"^\$(\S[^$\r\n]*?[^\s\\]{1}?)\$"),
+ "tmpl": "{0}",
+ "tag": "$",
+ "pre": dollar_pre,
+ "post": dollar_post,
+ },
+ {
+ "name": "math_single",
+ "rex": re.compile(r"^\$([^$\s\\]{1}?)\$"),
+ "tmpl": "{0}",
+ "tag": "$",
+ "pre": dollar_pre,
+ "post": dollar_post,
+ },
+ ],
+ "block": [
+ {
+ "name": "math_block_eqno",
+ "rex": re.compile(
+ r"^`{3}math\s+?([^`]+?)\s+?`{3}\s*?\(([^)$\r\n]+?)\)", re.M
+ ),
+ "tmpl": '',
+ "tag": "```math",
+ },
+ {
+ "name": "math_block",
+ "rex": re.compile(r"^`{3}math\s+?([^`]+?)\s+?`{3}", re.M),
+ "tmpl": "",
+ "tag": "```math",
+ },
+ ],
+ },
+ "kramdown": {
+ "inline": [
+ {
+ "name": "math_inline",
+ "rex": re.compile(r"^\${2}([^$\r\n]*?)\${2}"),
+ "tmpl": "{0}",
+ "tag": "$$",
+ }
+ ],
+ "block": [
+ {
+ "name": "math_block_eqno",
+ "rex": re.compile(r"^\${2}([^$]*?)\${2}\s*?\(([^)$\r\n]+?)\)", re.M),
+ "tmpl": '',
+ "tag": "$$",
+ },
+ {
+ "name": "math_block",
+ "rex": re.compile(r"^\${2}([^$]*?)\${2}", re.M),
+ "tmpl": "",
+ "tag": "$$",
+ },
+ ],
+ },
+ "dollars": {
+ "inline": [
+ {
+ "name": "math_inline",
+ "rex": re.compile(r"^\$(\S[^$]*?[^\s\\]{1}?)\$"),
+ "tmpl": "{0}",
+ "tag": "$",
+ "pre": dollar_pre,
+ "post": dollar_post,
+ },
+ {
+ "name": "math_single",
+ "rex": re.compile(r"^\$([^$\s\\]{1}?)\$"),
+ "tmpl": "{0}",
+ "tag": "$",
+ "pre": dollar_pre,
+ "post": dollar_post,
+ },
+ ],
+ "block": [
+ {
+ "name": "math_block_eqno",
+ "rex": re.compile(r"^\${2}([^$]*?)\${2}\s*?\(([^)$\r\n]+?)\)", re.M),
+ "tmpl": '\n', # noqa: E501
+ "tag": "$$",
+ },
+ {
+ "name": "math_block",
+ "rex": re.compile(r"^\${2}([^$]*?)\${2}", re.M),
+ "tmpl": "\n",
+ "tag": "$$",
+ },
+ ],
+ },
+}
diff --git a/tests/test_texmath.py b/tests/test_texmath.py
index d927793..70fdd53 100644
--- a/tests/test_texmath.py
+++ b/tests/test_texmath.py
@@ -15,7 +15,7 @@
def test_inline_func():
- inline_func = main.make_inline_func(main.rules.dollars.inline[0])
+ inline_func = main.make_inline_func(main.rules["dollars"]["inline"][0])
md = MarkdownIt()
src = r"$a=1$ $b=2$"
@@ -41,7 +41,7 @@ def test_inline_func():
def test_block_func():
- block_func = main.make_block_func(main.rules.dollars.block[0])
+ block_func = main.make_block_func(main.rules["dollars"]["block"][0])
md = MarkdownIt()
src = r"$$\na=1\n\nc\nb=2$$ (abc)"
tokens = []