From edbc1440cf9b40d8569efd239dd30d50a337cf2f Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 14 May 2025 21:46:37 +0200 Subject: add function TableEmpty() --- .../semantic-markdown/semantic-markdown.lua | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to '_extensions/ruc-play') diff --git a/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua b/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua index 42101b5..59195c2 100644 --- a/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua +++ b/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua @@ -111,6 +111,16 @@ -- @see os.setlocale 'C' +-- flag running with older release of Pandoc +-- +-- Some Pandoc features, +-- notably pandoc.List:at() introduced wit Pandoc 3.5, +-- are unavailable in older Pandoc releases still in widespread use +-- due to complexities of keeping Haskell dependencies in sync. +-- @see +local PANDOC_IS_OLD = PANDOC_VERSION[1] < 3 + or (PANDOC_VERSION[1] == 3 and PANDOC_VERSION[2] < 5) + --- pseudo-enum table to track parser enclosure state --- @see local Enclosure = { @@ -161,6 +171,22 @@ local CURIE_DEFAULT = ":" -- TODO: maybe support overriding context with a JSON-LD URI -- @see +--- TableEmpty - check if Pandoc List contains any elements +--- +--- Use a workaround for Pandoc releases older than 3.5 +--- where ergonomic function pandoc.List:at() is missing. +--- +--- @param list Pandoc List to inspect +--- @return result of inspection as boolean +local function TableEmpty(list) + if PANDOC_IS_OLD then + local list_clone = list:clone() + return not list_clone:remove() + else + return list:at(1) == nil + end +end + --- Namespaces - process RDF namespace IRI declarations --- --- Takes as input a list of Para block elements. @@ -422,7 +448,9 @@ local function Statements (block) end -- qualify completed bracketed enclosure - elems:extend(elems_enclosed) + if not TableEmpty(elems_enclosed) then + elems:extend(elems_enclosed) + end elems_enclosed = pandoc.List() elems_unenclosed = pandoc.List() -- cgit v1.2.3