aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-04-04 18:30:07 +0200
committerJonas Smedegaard <dr@jones.dk>2025-04-07 13:14:43 +0200
commitf95724d847653bde8858888852eb29ec6ce050a7 (patch)
treebb22cb080e925cf3f0057ac440fa33eb3437923f
parent8eb1bfa622f0ec8f046f38204f00b8923669f74e (diff)
use a single pos variable
-rw-r--r--_extensions/ruc-play/semantic-markdown/semantic-markdown.lua49
1 files changed, 28 insertions, 21 deletions
diff --git a/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua b/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua
index 7c76670..78480e6 100644
--- a/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua
+++ b/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua
@@ -147,9 +147,9 @@ end
--- @see <https://pandoc.org/lua-filters.html#type-inline>
function Statements (blocks)
- -- positions of beginning of enclosed content
- -- usable as flags, since it is always preceded by a marker
- local pos_bracketed, pos_braced
+ -- flags for enclosing stages
+ -- TODO: support nested bracket enclosure
+ local bracketed, braced
-- amount of detected statements in this block
local statement_count = 0
@@ -157,37 +157,44 @@ function Statements (blocks)
local new_inlines = {}
for i, el in ipairs(blocks.content) do
-
- -- enclosure marker positions within same inline
- local pos_bracket_begin, pos_brace_begin, pos_brace_end
+ local pos = 0
-- unenclosed, entering bracketed enclosure
- -- TODO: support nested bracket enclosure
- if el.t == 'Str' and not (pos_bracketed or pos_braced) then
- _, pos_bracket_begin = string.find(el.text, "%[")
- if pos_bracket_begin then
- pos_bracketed = pos_bracket_begin + 1
+ -- TODO: support nested bracketed enclosure
+ if el.t == 'Str' and not (bracketed or braced) then
+ _, pos = string.find(el.text, "%[")
+ if pos then
+ bracketed = 1
+ pos = pos + 1
end
end
-- in bracketed enclosure, entering braced enclosure
-- TODO: support nested bracket enclosure
- if el.t == 'Str' and pos_bracketed and not pos_braced then
- _, pos_brace_begin, s = string.find(el.text, "^([^%[%]}]*)%]{",
- pos_bracketed)
- if pos_brace_begin then
- pos_braced = pos_brace_begin + 1
- table.insert(new_inlines, pandoc.Str(s))
+ if el.t == 'Str' and bracketed and not braced then
+ _, pos, s = string.find(el.text, "^([^%[%]}]*)%]{?", pos)
+ if pos then
+
+ -- entering braced enclosure
+ if el.text:sub(pos, pos) == "{" then
+ braced = 1
+ pos = pos + 1
+ table.insert(new_inlines, pandoc.Str(s))
+
+ -- leaving non-annotation enclosure
+ else
+ bracketed = 0
+ braced = 0
+ end
end
end
-- in braced enclosure, leaving it
-- TODO: support mixed-use enclosure
-- TODO: cover curie_prefix and curie_local and curie_default
- if el.t == 'Str' and pos_braced then
- _, pos_brace_end = string.find(el.text, "^"..curie_long.."}",
- pos_braced)
- if pos_brace_end then
+ if el.t == 'Str' and braced then
+ _, pos = string.find(el.text, "^"..curie_long.."}", pos)
+ if pos then
statement_count = statement_count + 1
-- TODO: call same function with remains of Str
end