Module:Context-link

-- -- This module implements context-link templates. local p = {} local getArgs = require('Dev:Arguments').getArgs

-- Helper functions

local function findnamespace(link) local namespace = link:match('^(.-):')

if namespace then local namespaces = mw.site.namespaces[namespace] if namespaces then return namespaces.id       end end

return 0 end local function linkformat(link, display) local namespace = findnamespace(link, false) local colon

if namespace == 6 or namespace == 14 then colon = ':' else colon = '' end -- Find the display value. if not display then local page, section = link:match('^(.-)#(.*)$') if page then display = page .. ' § ' .. section end end -- Assemble the link. if display then return string.format('%s', colon, link, display) else return string.format('%s%s', colon, link) end end

-- Produces standard context-link text. function p.contextlink(frame) local args = getArgs(frame) local desc = args.desc or 'For another page, see' local links = {} for i, link in ipairs(args) do       local display = args['t' .. i]       table.insert(links, linkformat(link, display)) end

local options = {} options.extraclasses = args.class options.extrastyles = args.style return p._contextlink(desc, links, options) end

function p._contextlink(desc, links, options) local linktext = table.concat(links, ', ', 1, #links - 1)

if #links > 1 then linktext = linktext .. ' or ' end

linktext = linktext .. links[#links]

local container = mw.html.create('div') :addClass('context-link') :addClass(options.extraclasses) :cssText(options.extrastyles) :wikitext(desc .. ' ' .. linktext)

return tostring(container) end

return p --