Module:Section link/sandbox: Difference between revisions

Content deleted Content added
example
sync
Line 4:
 
local p = {}
 
--[[
For example:
Phonological_history_of English_consonants#.2Ft.E2.80.93r.2F_merger
Phonological_history_of English_consonants § /t–r/_merger
--]]
local function decodeAnchor(anchor)
if type(anchor) ~= "string" then
return nil
end
return (anchor:gsub(
"%.([0-9A-F][0-9A-F])", -- lowercase a-f is not used
function (hexByte)
return string.char(tonumber(hexByte, 16))
end))
end
 
 
local function makeSectionLink(page, section, display)
Line 62 ⟶ 44:
if #sections <= 1 then
local linkPage = page or ''
local section = decodeAnchor(sections[1]) or 'Notes'
local display = '§&nbsp;' .. section
if isShowingPage then
Line 85 ⟶ 67:
local ret = {}
for i, section in ipairs(sections) do
ret[i] = makeSectionLink(page, decodeAnchor(section))
end