Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Join the Playtest on Steam Now: SpiritVale

Module:Definitions: Difference between revisions

From SpiritVale Wiki
No edit summary
No edit summary
Tags: Reverted Mobile edit Mobile web edit
Line 143: Line 143:


return '<span class="sv-def-icon-img">[[' .. fileTitle .. '|15px|link=]]</span>'
return '<span class="sv-def-icon-img">[[' .. fileTitle .. '|15px|link=]]</span>'
end
-- =============================================================================
-- Link rendering
-- - If Link is present, render a real <a href="...">
-- - If Link is blank, render plain text
-- =============================================================================
local function link_to_href(link)
link = trim(link)
if link == "" then return nil end
-- External
if link:match("^https?://") or link:match("^//") then
return link
end
-- Internal: allow "Page#Fragment"
local page, frag = link:match("^(.-)#(.*)$")
if not page then
page = link
frag = nil
end
local t = mw.title.new(page)
if not t then
return nil
end
local url = t:localUrl()
if frag and frag ~= "" then
url = url .. "#" .. mw.uri.encode(frag, "WIKI")
end
return url
end
local function text_html(name, link)
name = tostring(name or "")
local href = link_to_href(link)
if href then
return '<a class="sv-def-text" href="' .. enc_attr(href) .. '">' .. mw.text.nowiki(name) .. '</a>'
end
return '<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>'
end
end


Line 205: Line 248:
'<span ' .. table.concat(attrs, " ") .. title_attr .. '>' ..
'<span ' .. table.concat(attrs, " ") .. title_attr .. '>' ..
icon_html(icon) ..
icon_html(icon) ..
'<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' ..
text_html(name, link) ..
'</span>'
'</span>'
end
end