mdit-py-plugins icon indicating copy to clipboard operation
mdit-py-plugins copied to clipboard

myst_role misparses trailing \

Open pennae opened this issue 2 years ago • 1 comments

Describe the bug

context

myst_role misparses inlines that begin with a role occurences and end with \ because its checks for leading \ unintentionally wraps around the end of srcCharCode and checks the last char code instead.

expectation

>>> md.render("{foo}`ar`\\")
'<p><code class="myst role">{foo}[ar]</code>\\</p>\n'

bug

>>> md.render("{foo}`ar`\\")
'<p>{foo}<code>ar</code>\\</p>\n'

problem This is a pretty clear misparse that causes rendering errors. admittedly it's not very likely to be hit in the grand scheme of things, but we've hit it nevertheless.

Reproduce the bug

render any string that contains only a myst_role followed by \, with no leading or trailing whitespace.

List your environment

  • markdown_it: 2.1.0
  • mdit_py_plugins: 0.3.3
  • python: 3.10.9
  • OS: nixos unstable

pennae avatar Jan 25 '23 15:01 pennae