Module:Dash: Difference between revisions
Jump to navigation
Jump to search
ArrowHead294 (talk | contribs) No edit summary |
ArrowHead294 (talk | contribs) No edit summary |
||
| Line 3: | Line 3: | ||
function p.dashes(frame) | function p.dashes(frame) | ||
local sp, se1, se2 | local sp, se1, se2 | ||
local s = frame.args["s"] | |||
local d = frame.args["d"] | |||
local d2 = frame.args["d2"] | |||
if | if s == "thin" then | ||
sp = " " -- U+2009 THIN SPACE | sp = " " -- U+2009 THIN SPACE | ||
elseif | elseif s == "hair" then | ||
sp = " " -- U+200A HAIR SPACE | sp = " " -- U+200A HAIR SPACE | ||
elseif | elseif s == "space" then | ||
sp = " " -- Regular space | sp = " " -- Regular space | ||
elseif | elseif s == "nbsp" then | ||
sp = " " -- U+00A0 NO-BREAK SPACE | sp = " " -- U+00A0 NO-BREAK SPACE | ||
elseif | elseif s == "nnbsp" then | ||
sp = " " -- U+202F NARROW NO-BREAK SPACE | sp = " " -- U+202F NARROW NO-BREAK SPACE | ||
else | else | ||
| Line 18: | Line 21: | ||
end | end | ||
if | if d == "long" then | ||
se1 = "—" -- U+2014 EM DASH | se1 = "—" -- U+2014 EM DASH | ||
elseif | elseif d == "med" or d == "medium" then | ||
se1 = "–" -- U+2013 EN DASH | se1 = "–" -- U+2013 EN DASH | ||
elseif | elseif d == "larr" then | ||
se1 = "←" -- U+2190 ← LEFTWARDS ARROW | se1 = "←" -- U+2190 ← LEFTWARDS ARROW | ||
elseif | elseif d == "rarr" then | ||
se1 = "→" -- U+2192 → RIGHTWARDS ARROW | se1 = "→" -- U+2192 → RIGHTWARDS ARROW | ||
else | else | ||
| Line 30: | Line 33: | ||
end | end | ||
if | if d2 == "long" then | ||
se2 = "—" -- U+2014 EM DASH | se2 = "—" -- U+2014 EM DASH | ||
elseif | elseif d2 == "med" or d2 == "medium" then | ||
se2 = "–" -- U+2013 EN DASH | se2 = "–" -- U+2013 EN DASH | ||
elseif | elseif d2 == "larr" then | ||
se2 = "←" -- U+2190 ← LEFTWARDS ARROW | se2 = "←" -- U+2190 ← LEFTWARDS ARROW | ||
elseif | elseif d2 == "rarr" then | ||
se2 = "→" -- U+2192 → RIGHTWARDS ARROW | se2 = "→" -- U+2192 → RIGHTWARDS ARROW | ||
elseif d2 == "short" then | |||
se1 = "-" -- Hyphen-minus | |||
else | else | ||
se2 = " | se2 = "" | ||
end | end | ||
local out_str = frame.args["input_str"]:gsub(",,%s+", sp .. se2 .. sp):gsub(",%s+", sp .. se1 .. sp) | local out_str = frame.args["input_str"] | ||
if se2 == "" then | |||
out_str = out_str:gsub(",+%s*,*%s+", sp .. se1 .. sp) | |||
else | |||
out_str = out_str:gsub(",%s*,%s+", sp .. se2 .. sp):gsub(",%s+", sp .. se1 .. sp) | |||
end | |||
return "<span>" .. out_str .. "</span>" | return "<span>" .. out_str .. "</span>" | ||
Revision as of 12:53, 23 May 2024
- This module should not be invoked directly; use its corresponding template instead: Template:Dash.
Replaces comma and space in list with dashes and spaces.
| Introspection summary for Module:Dash | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
No function descriptions were provided. The Lua code may have further information.
local p = {};
function p.dashes(frame)
local sp, se1, se2
local s = frame.args["s"]
local d = frame.args["d"]
local d2 = frame.args["d2"]
if s == "thin" then
sp = " " -- U+2009 THIN SPACE
elseif s == "hair" then
sp = " " -- U+200A HAIR SPACE
elseif s == "space" then
sp = " " -- Regular space
elseif s == "nbsp" then
sp = " " -- U+00A0 NO-BREAK SPACE
elseif s == "nnbsp" then
sp = " " -- U+202F NARROW NO-BREAK SPACE
else
sp = "" -- No space
end
if d == "long" then
se1 = "—" -- U+2014 EM DASH
elseif d == "med" or d == "medium" then
se1 = "–" -- U+2013 EN DASH
elseif d == "larr" then
se1 = "←" -- U+2190 ← LEFTWARDS ARROW
elseif d == "rarr" then
se1 = "→" -- U+2192 → RIGHTWARDS ARROW
else
se1 = "-" -- Hyphen-minus
end
if d2 == "long" then
se2 = "—" -- U+2014 EM DASH
elseif d2 == "med" or d2 == "medium" then
se2 = "–" -- U+2013 EN DASH
elseif d2 == "larr" then
se2 = "←" -- U+2190 ← LEFTWARDS ARROW
elseif d2 == "rarr" then
se2 = "→" -- U+2192 → RIGHTWARDS ARROW
elseif d2 == "short" then
se1 = "-" -- Hyphen-minus
else
se2 = ""
end
local out_str = frame.args["input_str"]
if se2 == "" then
out_str = out_str:gsub(",+%s*,*%s+", sp .. se1 .. sp)
else
out_str = out_str:gsub(",%s*,%s+", sp .. se2 .. sp):gsub(",%s+", sp .. se1 .. sp)
end
return "<span>" .. out_str .. "</span>"
end
return p