diff options
author | pennae <github@quasiparticle.net> | 2023-01-03 02:14:10 +0100 |
---|---|---|
committer | pennae <github@quasiparticle.net> | 2023-01-10 10:31:51 +0100 |
commit | 798b7fdc5cf07786c74a79e5c63b6ebcafed42eb (patch) | |
tree | b65fd173dd3c7b0f7851149412c184157a4c62a5 /doc | |
parent | dfdaa0ce26e1e29967a01e1900aba5b112fc087e (diff) |
doc/filters: fix myst-reader role detection
matching on only `{...}` does not trigger if the role tag is preceded by something usually considered a semantic separator that isn't a separator as markdown knows it, e.g. punctuation characters.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/build-aux/pandoc-filters/myst-reader/roles.lua | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/doc/build-aux/pandoc-filters/myst-reader/roles.lua b/doc/build-aux/pandoc-filters/myst-reader/roles.lua index c33a688eeba7a..f4ef6d390b40b 100644 --- a/doc/build-aux/pandoc-filters/myst-reader/roles.lua +++ b/doc/build-aux/pandoc-filters/myst-reader/roles.lua @@ -17,9 +17,16 @@ function Inlines(inlines) if correct_tags then -- docutils supports alphanumeric strings separated by [-._:] -- We are slightly more liberal for simplicity. - local role = first.text:match('^{([-._+:%w]+)}$') - if role ~= nil then - inlines:remove(i) + -- Allow preceding punctuation (eg '('), otherwise '({file}`...`)' + -- does not match. Also allow anything followed by a non-breaking space + -- since pandoc emits those after certain abbreviations (e.g. e.g.). + local prefix, role = first.text:match('^(.*){([-._+:%w]+)}$') + if role ~= nil and (prefix == '' or prefix:match("^.*[%p ]$") ~= nil) then + if prefix == '' then + inlines:remove(i) + else + first.text = prefix + end second.attributes['role'] = role second.classes:insert('interpreted-text') end |