Module:Dash: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
ArrowHead294 (talk | contribs)
No edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
local p = {}


function p.dashes(frame)
-- Main function that does the substitution
local sp = ""
function p._dash(in_str, s, d, d2)
local se = ""
local sp, se1, se2
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 frame.args["spaces"] == "thin" then
if d == "long" then
sp = " "
se1 = "—" -- U+2014 EM DASH
elseif frame.args["spaces"] == "hair" then
elseif d == "med" or d == "medium" then
sp = " "
se1 = "–" -- U+2013 EN DASH
elseif frame.args["spaces"] == "space" then
elseif d == "larr" or d == "oarr" then
sp = " "
se1 = "←"                                   -- U+2190 ← LEFTWARDS ARROW
elseif d == "rarr" or d == "iarr" then
se1 = "→"                                   -- U+2192 → RIGHTWARDS ARROW
else
else
sp = ""
se1 = "-" -- Hyphen-minus
end
end
if frame.args["separator"] == "mdash" then
if d2 == "long" then
se = "—"
se2 = "—" -- U+2014 EM DASH
elseif frame.args["separator"] == "ndash" then
elseif d2 == "med" or d2 == "medium" then
se = "–"
se2 = "–" -- U+2013 EN DASH
elseif d2 == "larr" or d == "iarr" then
se2 = "←"                                   -- U+2190 ← LEFTWARDS ARROW
elseif d2 == "rarr" or d == "oarr" then
se2 = "→"                                    -- U+2192 → RIGHTWARDS ARROW
elseif d2 == "short" then
se1 = "-" -- Hyphen-minus
else
else
se = "-"
se2 = ""
end
end
local out_str = sp .. se .. sp
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
return "<span>" .. frame.args["input_str"]:gsub("%s+", out_str) .. "</span>"
return frame:preprocess(result)
end
end


return p
return p

Latest revision as of 12:04, 1 June 2025

Module documentation[view] [edit] [history] [purge]
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 
Functions provided (2)
Line Function Params
4 _dash (main) (in_str, s, d, d2)
55 dashes (invokable) (frame)
Lua modules required (0)
Variable Module Functions used

No function descriptions were provided. The Lua code may have further information.


local p = {}

-- Main function that does the substitution
function p._dash(in_str, s, d, d2)
	local sp, se1, se2
	
	if s == "thin" then
    	sp = "&#x2009;"										-- U+2009 THIN SPACE
	elseif s == "hair" then
		sp = "&#x200A;"										-- U+200A HAIR SPACE
	elseif s == "space" then
		sp = " "											-- Regular space
	elseif s == "nbsp" then
	    sp = "&nbsp;"										-- U+00A0 NO-BREAK SPACE
    elseif s == "nnbsp" then
	    sp = "&#x202F;"										-- U+202F NARROW NO-BREAK SPACE
	else
		sp = ""												-- No space
	end
	
	if d == "long" then
		se1 = "&#x2014;"									-- U+2014 EM DASH
	elseif d == "med" or d == "medium" then
		se1 = "&#x2013;"									-- U+2013 EN DASH
	elseif d == "larr" or d == "oarr" then
		se1 = "&#x2190;"                                    -- U+2190 ← LEFTWARDS ARROW
	elseif d == "rarr" or d == "iarr" then
		se1 = "&#x2192;"                                    -- U+2192 → RIGHTWARDS ARROW
	else
		se1 = "-"											-- Hyphen-minus
	end
	
	if d2 == "long" then
		se2 = "&#x2014;"									-- U+2014 EM DASH
	elseif d2 == "med" or d2 == "medium" then
		se2 = "&#x2013;"									-- U+2013 EN DASH
	elseif d2 == "larr" or d == "iarr" then
		se2 = "&#x2190;"                                    -- U+2190 ← LEFTWARDS ARROW
	elseif d2 == "rarr" or d == "oarr" then
		se2 = "&#x2192;"                                    -- U+2192 → RIGHTWARDS ARROW
	elseif d2 == "short" then
		se1 = "-"											-- Hyphen-minus
	else
		se2 = ""
	end
	
	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
	
	return frame:preprocess(result)
end

return p