Module:Hatnote inline: Difference between revisions

From Wikitia
Jump to navigation Jump to search
m 1 revision imported
No edit summary
 
Line 9: Line 9:
local mHatnote = require('Module:Hatnote')
local mHatnote = require('Module:Hatnote')
local mArguments = require('Module:Arguments')
local mArguments = require('Module:Arguments')
local yesno = require('Module:Yesno')
 
-- FIX: Import yesno function correctly
local yesno
local success, result = pcall(require, 'Module:Yesno')
if success and type(result) == "table" then
    yesno = result._yesno or result.yesno
    if type(yesno) ~= "function" then
        yesno = function(val, default)
            if val == nil then return default end
            if type(val) == "boolean" then return val end
            if type(val) == "string" then
                val = val:lower():match('^%s*(.-)%s*$') or ""
                if val == 'yes' or val == 'y' or val == 'true' or val == 't' or val == 'on' or val == '1' then
                    return true
                elseif val == 'no' or val == 'n' or val == 'false' or val == 'f' or val == 'off' or val == '0' then
                    return false
                end
            elseif type(val) == "number" then
                if val == 1 then return true
                elseif val == 0 then return false end
            end
            return default
        end
    end
else
    yesno = function(val, default)
        if val == nil then return default end
        if type(val) == "boolean" then return val end
        if type(val) == "string" then
            val = val:lower():match('^%s*(.-)%s*$') or ""
            if val == 'yes' or val == 'y' or val == 'true' or val == 't' or val == 'on' or val == '1' then
                return true
            elseif val == 'no' or val == 'n' or val == 'false' or val == 'f' or val == 'off' or val == '0' then
                return false
            end
        elseif type(val) == "number" then
            if val == 1 then return true
            elseif val == 0 then return false end
        end
        return default
    end
end
 
local p = {}
local p = {}


Line 20: Line 62:
['</div>$'] = '</span>'
['</div>$'] = '</span>'
}
}
for k, v in pairs(subs) do hatnote = string.gsub(hatnote, k, v, 1) end
for k, v in pairs(subs) do  
hatnote = string.gsub(hatnote, k, v, 1)  
end
end
end
return hatnote
return hatnote

Latest revision as of 12:07, 1 May 2026

Documentation for this module may be created at Module:Hatnote inline/doc

--------------------------------------------------------------------------------
--                              Module:Hatnote-inline                         --
--                                                                            --
-- This module produces hatnote-style links, and links to related articles,	  --
-- but inside a <span>, instead of the <div> used by Module:Hatnote.  It      --
-- implements the {{hatnote-inline}} meta-template.                           --
--------------------------------------------------------------------------------

local mHatnote = require('Module:Hatnote')
local mArguments = require('Module:Arguments')

-- FIX: Import yesno function correctly
local yesno
local success, result = pcall(require, 'Module:Yesno')
if success and type(result) == "table" then
    yesno = result._yesno or result.yesno
    if type(yesno) ~= "function" then
        yesno = function(val, default)
            if val == nil then return default end
            if type(val) == "boolean" then return val end
            if type(val) == "string" then
                val = val:lower():match('^%s*(.-)%s*$') or ""
                if val == 'yes' or val == 'y' or val == 'true' or val == 't' or val == 'on' or val == '1' then
                    return true
                elseif val == 'no' or val == 'n' or val == 'false' or val == 'f' or val == 'off' or val == '0' then
                    return false
                end
            elseif type(val) == "number" then
                if val == 1 then return true
                elseif val == 0 then return false end
            end
            return default
        end
    end
else
    yesno = function(val, default)
        if val == nil then return default end
        if type(val) == "boolean" then return val end
        if type(val) == "string" then
            val = val:lower():match('^%s*(.-)%s*$') or ""
            if val == 'yes' or val == 'y' or val == 'true' or val == 't' or val == 'on' or val == '1' then
                return true
            elseif val == 'no' or val == 'n' or val == 'false' or val == 'f' or val == 'off' or val == '0' then
                return false
            end
        elseif type(val) == "number" then
            if val == 1 then return true
            elseif val == 0 then return false end
        end
        return default
    end
end

local p = {}

function p.hatnoteInline (frame)
	local args = mArguments.getArgs(frame)
	local hatnote = mHatnote.hatnote(frame)
	if args.inline == nil or yesno(args.inline, true) then
		local subs = {
			['<div'] = '<span',
			['</div>$'] = '</span>'
		}
		for k, v in pairs(subs) do 
			hatnote = string.gsub(hatnote, k, v, 1) 
		end
	end
	return hatnote
end

p.hatnote = p.hatnoteInline --alias

return p