File tree Expand file tree Collapse file tree
tests/fixtures/sources/bracketed_spans Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -428,10 +428,16 @@ def blocked(position: int) -> bool:
428428 return "" .join (written )
429429
430430
431- _SPAN = re .compile (r"\[([^\[\]\n]*)\]\{[^{}\n]*\}" )
431+ _ATTRIBUTE = r"""[.#][^\s{}]+|[\w-]+=(?:"[^"\n]*"|[^\s{}]+)"""
432+ """One attribute of a pandoc attribute list: a class, an id, or a key and its value."""
433+
434+ _SPAN = re .compile (rf"\[([^\[\]\n]*)\]\{{(?:{ _ATTRIBUTE } )(?: +(?:{ _ATTRIBUTE } ))*\}}" )
432435"""A bracketed span as ``commonmark_x`` writes one, opened and closed on the one line.
433436
434437The ``]{`` is what tells one from a link's ``](`` and from an image's ``){width=...}``.
438+ The braces must hold an attribute list, because LaTeX writes brackets before braces as
439+ well: ``$\\ sqrt[3]{x + 1}$`` is a cube root, and dropping its braces would leave
440+ ``$\\ sqrt3$``, which KaTeX renders and no check reports.
435441"""
436442
437443
@@ -471,6 +477,8 @@ def _spans_unwrapped(markdown: str) -> str:
471477 '::: {.solution}\nThe load is $F = pA$.\n:::\n'
472478 >>> _spans_unwrapped('{width="1in"}\n')
473479 '{width="1in"}\n'
480+ >>> _spans_unwrapped("The root is $\\sqrt[3]{x + 1}$.\n")
481+ 'The root is $\\sqrt[3]{x + 1}$.\n'
474482 """
475483 if "\r \n " in markdown :
476484 # Pandoc writes the line endings of whoever is running it, and the file on disk
Original file line number Diff line number Diff line change 1010"""
1111
1212if __name__ == "__main__" :
13+ from pathlib import Path
14+
1315 from docx import Document
1416 from docx .enum .text import WD_COLOR_INDEX
1517
3032 note .add_run ("Note: " ).font .small_caps = True
3133 note .add_run ("the oil is incompressible." )
3234
33- document .save ("source.docx" )
35+ # Beside this file, so that the fixture is written wherever the script is run from.
36+ document .save (Path (__file__ ).with_name ("source.docx" ))
You can’t perform that action at this time.
0 commit comments