Module:parse utilities: Difference between revisions

No edit summary
No edit summary
 
Line 538: Line 538:
local split_runs = export.split_alternating_runs_escaping(runs, splitchar, preserve_splitchar, escape_fun,
local split_runs = export.split_alternating_runs_escaping(runs, splitchar, preserve_splitchar, escape_fun,
unescape_fun)
unescape_fun)
for i = 1, #split_runs, (preserve_splitchar and 2 or 1) do
for i = 1, #split_runs do
split_runs[i] = concat(split_runs[i])
split_runs[i] = concat(split_runs[i])
end
end
Line 634: Line 634:
Parse a term that may have a language code (or possibly multiple plus-separated language codes, if
Parse a term that may have a language code (or possibly multiple plus-separated language codes, if
`data.allow_multiple` is given) preceding it (e.g. {la:minūtia} or {grc:[[σκῶρ|σκατός]]} or
`data.allow_multiple` is given) preceding it (e.g. {la:minūtia} or {grc:[[σκῶρ|σκατός]]} or
{nan-hbl+hak:[[毋]][[知]]}). Return four arguments:
{nan-hbl+hak:[[毋]][[知]]}). Return five arguments:
# the term minus the language code;
# the original prefixed term; in the case of a Wikipedia or Wikisource prefix followed by a two-part link, it is a
  two-part link with the Wikipedia/Wikisource prefix moved inside the link; in the case of a Wikipedia or Wikisource
  prefix followed by a redundant one-part link, the brackets are removed;
# the language object corresponding to the language code (possibly a family object if `data.allow_family` is given), or
# the language object corresponding to the language code (possibly a family object if `data.allow_family` is given), or
   a list of such objects if `data.allow_multiple` is given;
   a list of such objects if `data.allow_multiple` is given;
# the link if the term is of the form {[[<var>link</var>|<var>display</var>]]} (it may be generated into that form with
# the link if the unprefixed term is of the form <code>[[<var>link</var>|<var>display</var>]]</code> or of the form
  Wikipedia and Wikisource prefixes) or of the form {{[[<var>link</var>]]}, otherwise the full term;
  <code>[[<var>link</var>]]</code>, otherwise the full unprefixed term;
# the display part if the term is of the form {[[<var>link</var>|<var>display</var>]]}, otherwise nil.
# the display part if the term is of the form <code>[[<var>link</var>|<var>display</var>]]</code> or has a Wikipedia or
  Wikisource prefix (in which case the part minus the prefix and any following language code will be returned, with
  redundant brackets stripped), else {nil};
# {true} if the term has a Wikipedia/Wikisource prefix, else {false}.
Etymology-only languages are always allowed. This function also correctly handles Wikipedia prefixes (e.g.
Etymology-only languages are always allowed. This function also correctly handles Wikipedia prefixes (e.g.
{w:Abatemarco} or {w:it:Colle Val d'Elsa} or {lw:ru:Филарет}) and Wikisource prefixes (e.g. {s:Twelve O'Clock} or
{w:Abatemarco} or {w:it:Colle Val d'Elsa} or {lw:ru:Филарет}) and Wikisource prefixes (e.g. {s:Twelve O'Clock} or
Line 697: Line 702:
local lang = wiki_links and get_lang(foreign_wiki, parse_err, "allow etym") or nil
local lang = wiki_links and get_lang(foreign_wiki, parse_err, "allow etym") or nil
local prefixed_link = wiki_prefix .. link
local prefixed_link = wiki_prefix .. link
return ("[[%s|%s]]"):format(prefixed_link, display or link), lang, prefixed_link, display
if display then
return ("[[%s|%s]]"):format(prefixed_link, display), lang, prefixed_link, display, true
else
-- Return the link minus any language codes as the fourth term (display form). Previously we returned `actual_term`
-- but this causes problems with redundant Wikipedia links of the form `w:[[Dragon Ball Z]]`. Don't generate a
-- two-part link so you can specify a display form in 3=. Note that the fourth and fifth params are currently only
-- used in [[Module:quote]].
return prefixed_link, lang, prefixed_link, link, true
end
end
end


Line 792: Line 805:
end
end
local link, display = parse_bracketed_term(term, parse_err)
local link, display = parse_bracketed_term(term, parse_err)
return term, termlang, link, display
return term, termlang, link, display, false
end
end


Line 1,102: Line 1,115:
if props.param_mods[prefix] then
if props.param_mods[prefix] then
local mod_props = props.param_mods[prefix]
local mod_props = props.param_mods[prefix]
if mod_props.replaced_by == false then
prefix_parse_err(
("Prefix has been removed and is no longer valid%s%s"):format(
mod_props.reason and ", " .. mod_props.reason or "",
mod_props.instead and "; instead, " .. mod_props.instead or "")
)
elseif mod_props.replaced_by then
prefix_parse_err(
("Prefix has been replaced by '%s'%s"):format(
mod_props.replaced_by, mod_props.reason and ", " .. mod_props.reason or "")
)
end
local key = mod_props.item_dest or prefix
local key = mod_props.item_dest or prefix
local dest
local dest