aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-06-20 10:48:59 +0200
committerJonas Smedegaard <dr@jones.dk>2025-06-20 10:48:59 +0200
commitda6d3bf212a91a2f9e8cc3dc96e930eabd203af8 (patch)
tree206bcc58223b24ab05ee6b4d42707cca44c08901
parent63eb9a7c17bf394d8ef24b475f72882ccf5da868 (diff)
extract Str text once
-rw-r--r--sem-md/sem-md.lua30
1 files changed, 16 insertions, 14 deletions
diff --git a/sem-md/sem-md.lua b/sem-md/sem-md.lua
index 1423fcf..82be5e9 100644
--- a/sem-md/sem-md.lua
+++ b/sem-md/sem-md.lua
@@ -410,6 +410,8 @@ local function Statements (block)
goto continue
end
+ local str = el.text
+
-- unenclosed immediately after enclosure
if encl == Enclosure.BRACED_DONE then
@@ -430,12 +432,12 @@ local function Statements (block)
-- unenclosed
-- TODO: accept backslash except immediately before bracket
if encl == Enclosure.NONE then
- local _, nextpos, s = el.text:find("^([^%[{\\]*)")
+ local _, nextpos, s = str:find("^([^%[{\\]*)")
pos = nextpos and nextpos + 1 or pos + 1
chars_unenclosed = chars_unenclosed..s
-- entering bracketed or braced enclosure
- local t = el.text:sub(pos, pos)
+ local t = str:sub(pos, pos)
if t == "[" or t == "{" then
-- qualify unenclosed elements
@@ -461,13 +463,13 @@ local function Statements (block)
-- TODO: accept backslash except immediately before bracket/brace
-- TODO: support nested bracket enclosure
if encl == Enclosure.BRACKETED then
- local _, nextpos, s = el.text:find("^([^%[%]}\\]*)", pos)
+ local _, nextpos, s = str:find("^([^%[%]}\\]*)", pos)
pos = nextpos and nextpos + 1 or pos + 1
chars_unenclosed = chars_unenclosed..s
chars_enclosed = chars_enclosed..s
-- exiting bracketed enclosure
- if el.text:sub(pos, pos) == "]" then
+ if str:sub(pos, pos) == "]" then
pos = pos + 1
chars_unenclosed = chars_unenclosed.."]"
encl = Enclosure.BRACKETED_DONE
@@ -478,7 +480,7 @@ local function Statements (block)
if encl == Enclosure.BRACKETED_DONE then
-- entering braced enclosure
- if el.text:sub(pos, pos) == "{" then
+ if str:sub(pos, pos) == "{" then
pos = pos + 1
chars_unenclosed = chars_unenclosed.."{"
encl = Enclosure.BRACED
@@ -508,11 +510,11 @@ local function Statements (block)
local curie_pattern3 = "^"..CURIE_TYPE_PREFIX..CURIE_LOCAL.."}"
local curie_pattern4 = "^"..CURIE_TYPE_PREFIX..CURIE_DEFAULT.."}"
local curie_pattern5 = "^"..CURIE_TYPE_PREFIX.."<[^<>]*>}"
- local _, nextpos1 = el.text:find(curie_pattern1, pos)
- local _, nextpos2 = el.text:find(curie_pattern2, pos)
- local _, nextpos3 = el.text:find(curie_pattern3, pos)
- local _, nextpos4 = el.text:find(curie_pattern4, pos)
- local _, nextpos5 = el.text:find(curie_pattern5, pos)
+ local _, nextpos1 = str:find(curie_pattern1, pos)
+ local _, nextpos2 = str:find(curie_pattern2, pos)
+ local _, nextpos3 = str:find(curie_pattern3, pos)
+ local _, nextpos4 = str:find(curie_pattern4, pos)
+ local _, nextpos5 = str:find(curie_pattern5, pos)
local nextpos = nextpos1 or nextpos2 or nextpos3 or nextpos4 or nextpos5
if nextpos then
if chars_enclosed:len() > 0 then
@@ -531,10 +533,10 @@ local function Statements (block)
-- postpone braced-only enclosure maybe at end of block
else
- chars_unenclosed = chars_unenclosed..el.text:sub(pos, nextpos)
+ chars_unenclosed = chars_unenclosed .. str:sub(pos, nextpos)
elems_unenclosed:insert(pandoc.Str(chars_unenclosed))
- chars_unenclosed = el.text:sub(nextpos + 1)
- chars_enclosed = el.text:sub(nextpos + 1)
+ chars_unenclosed = str:sub(nextpos + 1)
+ chars_enclosed = str:sub(nextpos + 1)
encl = Enclosure.BRACED_DONE
goto continue
@@ -543,7 +545,7 @@ local function Statements (block)
elems_enclosed = pandoc.List()
elems_unenclosed = pandoc.List()
chars_enclosed = ""
- chars_unenclosed = el.text:sub(nextpos + 1)
+ chars_unenclosed = str:sub(nextpos + 1)
encl = Enclosure.BRACED_DONE
block_has_diverged = true