Module:Dash: Difference between revisions
ArrowHead294 (talk | contribs) No edit summary |
ArrowHead294 (talk | contribs) mNo edit summary |
||
| (9 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p. | -- Main function that does the substitution | ||
function p._dash(in_str, s, d, d2) | |||
local sp, se1, se2 | local sp, se1, se2 | ||
if s == "thin" then | if s == "thin" then | ||
| Line 25: | Line 23: | ||
elseif d == "med" or d == "medium" then | elseif d == "med" or d == "medium" then | ||
se1 = "–" -- U+2013 EN DASH | se1 = "–" -- U+2013 EN DASH | ||
elseif d == "larr" then | elseif d == "larr" or d == "oarr" then | ||
se1 = "←" -- U+2190 ← LEFTWARDS ARROW | se1 = "←" -- U+2190 ← LEFTWARDS ARROW | ||
elseif d == "rarr" then | elseif d == "rarr" or d == "iarr" then | ||
se1 = "→" -- U+2192 → RIGHTWARDS ARROW | se1 = "→" -- U+2192 → RIGHTWARDS ARROW | ||
else | else | ||
| Line 37: | Line 35: | ||
elseif d2 == "med" or d2 == "medium" then | elseif d2 == "med" or d2 == "medium" then | ||
se2 = "–" -- U+2013 EN DASH | se2 = "–" -- U+2013 EN DASH | ||
elseif d2 == "larr" then | elseif d2 == "larr" or d == "iarr" then | ||
se2 = "←" -- U+2190 ← LEFTWARDS ARROW | se2 = "←" -- U+2190 ← LEFTWARDS ARROW | ||
elseif d2 == "rarr" then | elseif d2 == "rarr" or d == "oarr" then | ||
se2 = "→" -- U+2192 → RIGHTWARDS ARROW | se2 = "→" -- U+2192 → RIGHTWARDS ARROW | ||
elseif d2 == "short" then | elseif d2 == "short" then | ||
| Line 47: | Line 45: | ||
end | end | ||
local | local result = ((se2 == nil or se2 == "") | ||
and in_str:gsub("[,|%s]*,%s+", sp .. se1 .. sp) | |||
or in_str:gsub(",%s*,%s+", sp .. se2 .. sp):gsub(",%s+", sp .. se1 .. sp)) | |||
return result | |||
end | |||
-- Wrapper function for Template:Dash | |||
function p.dashes(frame) | |||
local s = frame.args["s"] | |||
local d = frame.args["d"] | |||
local d2 = frame.args["d2"] | |||
local in_str = frame.args["input_str"] | |||
local debugg = frame.args["debug"] | |||
local result = p._dash(in_str, s, d, d2) | |||
if debugg == true then | |||
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" | |||
end | end | ||
return | return frame:preprocess(result) | ||
end | end | ||
return p | return p | ||