Модуль:Якорь: различия между версиями
Перейти к навигации
Перейти к поиску
https://belgen.info/wiki>Grain of sand (модуль: -предел на 10 якорей) |
Admin (обсуждение | вклад) м (1 версия импортирована) |
||
(не показано 5 промежуточных версий 3 участников) | |||
Строка 1: | Строка 1: | ||
{ | local getArgs = require('Module:Arguments').getArgs | ||
{ | local yesno = require('Module:Yesno') | ||
local compressSparseArray = require('Module:TableTools').compressSparseArray | |||
local p = {} | |||
local function unpack(...) | |||
local frame = ... | |||
local args | |||
if type(frame.args) == 'table' then | |||
args = getArgs(frame) | |||
elseif type(frame) == 'table' then | |||
args = frame | |||
else | |||
args = {...} | |||
end | |||
return args | |||
end | |||
function p._main(anchor, text, visible) | |||
local result = mw.html.create('span') | |||
:attr('id', anchor) | |||
:wikitext(text) | |||
if visible then | |||
result:addClass('highlight-target') | |||
end | |||
return tostring(result) | |||
end | |||
function p.main(...) | |||
local args = unpack(...) | |||
local anchors = compressSparseArray(args) | |||
local text | |||
local visible = yesno(args.visible or args.v) | |||
if visible then | |||
text = args.text or args['текст'] or args[1] | |||
end | |||
local result = text | |||
for i, v in ipairs(anchors) do | |||
result = p._main(anchors[i], result, visible) | |||
end | |||
return result | |||
end | |||
return p |
Текущая версия от 17:22, 24 мая 2025
Для документации этого модуля может быть создана страница Модуль:Якорь/doc
local getArgs = require('Module:Arguments').getArgs local yesno = require('Module:Yesno') local compressSparseArray = require('Module:TableTools').compressSparseArray local p = {} local function unpack(...) local frame = ... local args if type(frame.args) == 'table' then args = getArgs(frame) elseif type(frame) == 'table' then args = frame else args = {...} end return args end function p._main(anchor, text, visible) local result = mw.html.create('span') :attr('id', anchor) :wikitext(text) if visible then result:addClass('highlight-target') end return tostring(result) end function p.main(...) local args = unpack(...) local anchors = compressSparseArray(args) local text local visible = yesno(args.visible or args.v) if visible then text = args.text or args['текст'] or args[1] end local result = text for i, v in ipairs(anchors) do result = p._main(anchors[i], result, visible) end return result end return p