Skip to content

Commit

Permalink
Fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
zepinglee committed Aug 13, 2024
1 parent a006642 commit f51e575
Showing 1 changed file with 45 additions and 34 deletions.
79 changes: 45 additions & 34 deletions citeproc/citeproc-output.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<span class="nocase">'
+ lpeg.P '<span class="nodecor">'
+ lpeg.P '<span style="font-variant:small-caps;">'
+ lpeg.P '<sc>'
+ lpeg.P '<i>'
+ lpeg.P '<b>'
+ lpeg.P '<sup>'
+ lpeg.P '<sub>'
+ lpeg.P ' "'
+ lpeg.P " '"
+ lpeg.P '("'
+ lpeg.P "('"
+ lpeg.P ""
+ lpeg.P ""
+ lpeg.P '</span>'
+ lpeg.P '</sc>'
+ lpeg.P '</i>'
+ lpeg.P '</b>'
+ lpeg.P '</sup>'
+ lpeg.P '</sub>'
+ 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("<code>") * Cp()) * ((1 - P("</code>")) ^ 0) *
Ct(Cp() * P("</code>") * Cp())
+ Ct(Cp() * P("<script>") * Cp()) * ((1 - P("</script>")) ^ 0) *
Ct(Cp() * P("</script>") * Cp())
+ Ct(Cp() * P("<pre>") * Cp()) * ((1 - P("</pre>")) ^ 0) *
Ct(Cp() * P("</pre>") * Cp())
local basic_tag_pattern = P '<span class="nocase">'
+ P '<span class="nodecor">'
+ P '<span style="font-variant:small-caps;">'
+ P '<sc>'
+ P '<i>'
+ P '<b>'
+ P '<sup>'
+ P '<sub>'
+ P ' "'
+ P " '"
+ P '("'
+ P "('"
+ P ""
+ P ""
+ P '</span>'
+ P '</sc>'
+ P '</i>'
+ P '</b>'
+ P '</sup>'
+ P '</sub>'
+ P '"'
+ P "'"
+ P ""
+ P ""

local default_tag_pattern = Ct((code_pattern + Ct(Cp() * basic_tag_pattern * Cp()) + P(1)) ^ 0)

local default_openers_info = {
['<span class="nocase">'] = {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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 == "<code>" then
return Code:new("")
return Code:new(inlines[1].value)
elseif tag == "<script>" then
return Code:new("")
return Code:new(inlines[1].value)
elseif tag == "<pre>" then
return Code:new("")
return Code:new(inlines[1].value)
else
error(string.format("Invalid tag '%s'", tag))
return PlainText:new("")
Expand Down

0 comments on commit f51e575

Please sign in to comment.