From f51e5758fdf8a4ab426f749210e2104a5b40c2e0 Mon Sep 17 00:00:00 2001 From: Zeping Lee Date: Tue, 13 Aug 2024 23:55:16 +0800 Subject: [PATCH] Fix code --- citeproc/citeproc-output.lua | 79 ++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/citeproc/citeproc-output.lua b/citeproc/citeproc-output.lua index 6df7ebb..73b1ecc 100644 --- a/citeproc/citeproc-output.lua +++ b/citeproc/citeproc-output.lua @@ -415,34 +415,45 @@ function InlineElement:parse_csl_rich_text(text) end +local P = lpeg.P +local Ct = lpeg.Ct +local Cp = lpeg.Cp + -- Lua's regex doesn't support groups and thus we have to implement the same -- logic with `lpeg`. -local basic_tag_pattern = lpeg.P '' - + lpeg.P '' - + lpeg.P '' - + lpeg.P '' - + lpeg.P '' - + lpeg.P '' - + lpeg.P '' - + lpeg.P '' - + lpeg.P ' "' - + lpeg.P " '" - + lpeg.P '("' - + lpeg.P "('" - + lpeg.P "“" - + lpeg.P "‘" - + lpeg.P '' - + lpeg.P '' - + lpeg.P '' - + lpeg.P '' - + lpeg.P '' - + lpeg.P '' - + lpeg.P '"' - + lpeg.P "'" - + lpeg.P "”" - + lpeg.P "’" - -local default_tag_pattern = lpeg.Ct((lpeg.Ct(lpeg.Cp() * basic_tag_pattern * lpeg.Cp()) + lpeg.P(1)) ^ 0) +local code_pattern = + Ct(Cp() * P("") * Cp()) * ((1 - P("")) ^ 0) * + Ct(Cp() * P("") * Cp()) + + Ct(Cp() * P("")) ^ 0) * + Ct(Cp() * P("") * Cp()) + + Ct(Cp() * P("
") * Cp()) * ((1 - P("
")) ^ 0) * + Ct(Cp() * P("") * Cp()) +local basic_tag_pattern = P '' + + P '' + + P '' + + P '' + + P '' + + P '' + + P '' + + P '' + + P ' "' + + P " '" + + P '("' + + P "('" + + P "“" + + P "‘" + + P '' + + P '' + + P '' + + P '' + + P '' + + P '' + + P '"' + + P "'" + + P "”" + + P "’" + +local default_tag_pattern = Ct((code_pattern + Ct(Cp() * basic_tag_pattern * Cp()) + P(1)) ^ 0) local default_openers_info = { [''] = { @@ -524,8 +535,8 @@ local function make_locale_tag_info(locale, context) local openers_info = util.deep_copy(default_openers_info) if localed_quotes.outer_open and localed_quotes.outer_close then - tag_pattern = tag_pattern + lpeg.P(_quoted(localed_quotes.outer_open)) - tag_pattern = tag_pattern + lpeg.P(_quoted(localed_quotes.outer_close)) + tag_pattern = tag_pattern + P(_quoted(localed_quotes.outer_open)) + tag_pattern = tag_pattern + P(_quoted(localed_quotes.outer_close)) openers_info[localed_quotes.outer_open] = { closer = localed_quotes.outer_close, @@ -535,8 +546,8 @@ local function make_locale_tag_info(locale, context) end if localed_quotes.inner_open and localed_quotes.inner_close then - tag_pattern = tag_pattern + lpeg.P(_quoted(localed_quotes.inner_open)) - tag_pattern = tag_pattern + lpeg.P(_quoted(localed_quotes.inner_close)) + tag_pattern = tag_pattern + P(_quoted(localed_quotes.inner_open)) + tag_pattern = tag_pattern + P(_quoted(localed_quotes.inner_close)) openers_info[localed_quotes.inner_open] = { closer = localed_quotes.inner_close, @@ -546,7 +557,7 @@ local function make_locale_tag_info(locale, context) end context.engine.locale_tags_info_dict[locale] = { - tag_pattern = lpeg.Ct((lpeg.Ct(lpeg.Cp() * tag_pattern * lpeg.Cp()) + lpeg.P(1)) ^ 0), + tag_pattern = Ct((code_pattern + Ct(Cp() * tag_pattern * Cp()) + P(1)) ^ 0), openers_info = openers_info, } end @@ -656,11 +667,11 @@ local function make_inline_from_tag(tag, inlines, openers_info, context) local localized_quotes = context:get_localized_quotes() return Quoted:new(inlines, localized_quotes, openers_info[tag].inner) elseif tag == "" then - return Code:new("") + return Code:new(inlines[1].value) elseif tag == "