fix link labels and persist in citeq_args
This commit is contained in:
parent
b45a3cba82
commit
f057618b52
1 changed files with 11 additions and 5 deletions
|
|
@ -1020,16 +1020,22 @@ local function _cite_q (citeq_args)
|
|||
end
|
||||
|
||||
for k, v in pairs(citeq_args) do
|
||||
if v == "" then citeq_args[k] = nil end -- remove blank parameters
|
||||
local link = tostring (v):match ('%[%[([^|]+)|%1%]%]'); -- get <link> from <v> wikilink [[<link>|<label>]] when <link> and <label> are same value
|
||||
if link then -- if <link> and <label> are the same thing
|
||||
citeq_args[k] = '[[' .. link .. ']]'; -- rewrite <v> as [[<link>]]
|
||||
if v == "" then
|
||||
citeq_args[k] = nil; -- remove blank parameters
|
||||
|
||||
elseif 'string' == type (v) then -- here when not blank; must be a string; |pmid= and the like are type 'number'
|
||||
local changed; -- flag is a number when changes have been made; nil else
|
||||
local pattern = '%[%[([^|]+)|%1%]%]'; -- pattern that looks for [[<link>|<label>]] wikilinks where <link> and <label> are identical
|
||||
v, changed = v:gsub (pattern, '[[%1]]'); -- where <link> and <label> are identical, rewrite all such [[<link>|<label>]] wikilinks in <v> using [[<link>]]
|
||||
|
||||
if changed then -- when changes have been made
|
||||
citeq_args[k] = v; -- update <citeq_args[k]>
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- if |expand=<anything>, write a nowiki'd version to see what the {{citation}} template call looks like
|
||||
if expand then
|
||||
|
||||
local expand_args = { "{{" .. (template and ("Cite "..template) or "Citation") } -- init with citation template
|
||||
if expand == "self" then
|
||||
citeq_args.id = old_id -- restore original |id= parameter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue