De Muysc cubun - Lengua Muisca

m
m
 
(No se muestran 2 ediciones intermedias del mismo usuario)
Línea 3: Línea 3:
  
 
local function getArg(frame, name, default)
 
local function getArg(frame, name, default)
    -- Lee primero del #invoke, luego del padre (si existe)
 
 
     local v = (frame.args and frame.args[name]) or ''
 
     local v = (frame.args and frame.args[name]) or ''
 
     if v == '' and frame.getParent then
 
     if v == '' and frame.getParent then
Línea 21: Línea 20:
 
     local suffix  = getArg(frame, 'suffix', '')
 
     local suffix  = getArg(frame, 'suffix', '')
 
     local doSort  = getArg(frame, 'sort', '') ~= ''
 
     local doSort  = getArg(frame, 'sort', '') ~= ''
 +
    -- NUEVO: base para enlaces externos (déjalo vacío para enlaces internos)
 +
    local base    = getArg(frame, 'base', '')  -- ej.: 'https://es.wikipedia.org/wiki/'
 +
    -- NUEVO: envoltorio para poder forzar target=_blank vía Common.js
 +
    local wrapCls = getArg(frame, 'class', 'll-newtab')
 +
    local newtab  = getArg(frame, 'newtab', '') ~= ''
  
 
     if valores == '' then
 
     if valores == '' then
 
         return '⚠️ LinkList: sin "valores".'
 
         return '⚠️ LinkList: sin "valores".'
 +
    end
 +
 +
    -- Normaliza el separador: si es solo coma, añade espacio
 +
    if outsep == ',' or outsep:match('^,%s*$') then
 +
        outsep = ', '
 
     end
 
     end
  
Línea 44: Línea 53:
 
         target = prefix .. target .. suffix
 
         target = prefix .. target .. suffix
 
         local full = (lead ~= '' and ':' or '') .. ns .. target
 
         local full = (lead ~= '' and ':' or '') .. ns .. target
         table.insert(out, string.format('[[%s|%s]]', full, label))
+
 
 +
         if base ~= '' then
 +
            -- Enlace EXTERNO: convierte espacios a guiones bajos para que la URL sea válida
 +
            local urlTitle = full:gsub(' ', '_')
 +
            table.insert(out, string.format('[%s%s %s]', base, urlTitle, label))
 +
        else
 +
            -- Enlace INTERNO wiki
 +
            table.insert(out, string.format('[[%s|%s]]', full, label))
 +
        end
 
     end
 
     end
  
     if #out == 0 then
+
    local text = table.concat(out, outsep)
         return '⚠️ LinkList: no hay elementos tras procesar.'
+
     if newtab then
 +
         text = string.format('<span class="%s">%s</span>', wrapCls, text)
 
     end
 
     end
     return table.concat(out, outsep)
+
     return text
 
end
 
end
  
 
return p
 
return p

Revisión actual - 20:01 12 sep 2025

La documentación para este módulo puede ser creada en Módulo:LinkList/doc

-- Módulo:LinkList
local p = {}

local function getArg(frame, name, default)
    local v = (frame.args and frame.args[name]) or ''
    if v == '' and frame.getParent then
        local parent = frame:getParent()
        if parent and parent.args then v = parent.args[name] or '' end
    end
    if v == '' then v = default or '' end
    return v
end

function p.links(frame)
    local valores = getArg(frame, 'valores', '')
    local outsep  = getArg(frame, 'sep', ', ')
    local ns      = getArg(frame, 'ns', '')
    local lead    = getArg(frame, 'leadcolon', '')
    local prefix  = getArg(frame, 'prefix', '')
    local suffix  = getArg(frame, 'suffix', '')
    local doSort  = getArg(frame, 'sort', '') ~= ''
    -- NUEVO: base para enlaces externos (déjalo vacío para enlaces internos)
    local base    = getArg(frame, 'base', '')  -- ej.: 'https://es.wikipedia.org/wiki/'
    -- NUEVO: envoltorio para poder forzar target=_blank vía Common.js
    local wrapCls = getArg(frame, 'class', 'll-newtab')
    local newtab  = getArg(frame, 'newtab', '') ~= ''

    if valores == '' then
        return '⚠️ LinkList: sin "valores".'
    end

    -- Normaliza el separador: si es solo coma, añade espacio
    if outsep == ',' or outsep:match('^,%s*$') then
        outsep = ', '
    end

    local items = {}
    for tok in mw.text.gsplit(valores, ',', true) do
        tok = mw.text.trim(tok)
        if tok ~= '' then table.insert(items, tok) end
    end

    if doSort then
        table.sort(items, function(a,b)
            return mw.ustring.lower(a) < mw.ustring.lower(b)
        end)
    end

    local out = {}
    for _, it in ipairs(items) do
        local target, label = it:match('^(.-)|(.+)$')
        if not target then target, label = it, it end
        target = prefix .. target .. suffix
        local full = (lead ~= '' and ':' or '') .. ns .. target

        if base ~= '' then
            -- Enlace EXTERNO: convierte espacios a guiones bajos para que la URL sea válida
            local urlTitle = full:gsub(' ', '_')
            table.insert(out, string.format('[%s%s %s]', base, urlTitle, label))
        else
            -- Enlace INTERNO wiki
            table.insert(out, string.format('[[%s|%s]]', full, label))
        end
    end

    local text = table.concat(out, outsep)
    if newtab then
        text = string.format('<span class="%s">%s</span>', wrapCls, text)
    end
    return text
end

return p