‼️ BREAKING: Add `attrs` argument to highligh callback The highligh callback should not have the signature: `highlight(code, lang, attrs)`. Implements: https://github.com/markdown-it/markdown-it/commit/866fba34a2f5eca294ec13b498ea72f1915b2421
diff --git a/markdown_it/renderer.py b/markdown_it/renderer.py index aa24f08..4207d71 100644 --- a/markdown_it/renderer.py +++ b/markdown_it/renderer.py
@@ -219,14 +219,19 @@ token = tokens[idx] info = unescapeAll(token.info).strip() if token.info else "" langName = "" + langAttrs = "" if info: langName = info.split()[0] + arr = info.split(maxsplit=1) + langName = arr[0] + if len(arr) == 2: + langAttrs = arr[1] if options.highlight: - highlighted = options.highlight(token.content, langName) or escapeHtml( - token.content - ) + highlighted = options.highlight( + token.content, langName, langAttrs + ) or escapeHtml(token.content) else: highlighted = escapeHtml(token.content)
diff --git a/tests/test_port/test_misc.py b/tests/test_port/test_misc.py new file mode 100644 index 0000000..f5f821e --- /dev/null +++ b/tests/test_port/test_misc.py
@@ -0,0 +1,14 @@ +from markdown_it import MarkdownIt +from markdown_it import presets + + +def test_highlight_arguments(): + def highlight_func(str_, lang, attrs): + assert lang == "a" + assert attrs == "b c d" + return "<pre><code>==" + str_ + "==</code></pre>" + + conf = presets.commonmark.make() + conf["options"]["highlight"] = highlight_func + md = MarkdownIt(config=conf) + assert md.render("``` a b c d \nhl\n```") == "<pre><code>==hl\n==</code></pre>\n"