Jump to content

Module:Hatnote inline/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
sync
borrow some code from the frame version in module:hatnote to clean this up a bit
Line 14: Line 14:
function p.hatnoteInline (frame)
function p.hatnoteInline (frame)
local args = mArguments.getArgs(frame)
local args = mArguments.getArgs(frame)
local hatnote = mHatnote.hatnote(frame)
local s = args[1]
if not s then
return p.makeWikitextError(
'no text specified',
'Template:Hatnote#Errors',
args.category
)
end
local options = {
extraclasses = args.extraclasses,
selfref = args.selfref,
inline = 0
}
if args.inline == nil or yesno(args.inline, true) then
if args.inline == nil or yesno(args.inline, true) then
local subs = {
options.inline = 1
['<div'] = '<span',
['</div>$'] = '</span>'
}
for k, v in pairs(subs) do hatnote = string.gsub(hatnote, k, v, 1) end
end
end
return hatnote
return mHatnote._hatnote(s, options)
end
end



Revision as of 21:50, 12 July 2021

--------------------------------------------------------------------------------
--                              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')
local yesno = require('Module:Yesno')
local p = {}

function p.hatnoteInline (frame)
	local args = mArguments.getArgs(frame)
	local s = args[1]
	if not s then
		return p.makeWikitextError(
			'no text specified',
			'Template:Hatnote#Errors',
			args.category
		)
	end
	local options = {
		extraclasses = args.extraclasses,
		selfref = args.selfref,
		inline = 0
	}
	
	if args.inline == nil or yesno(args.inline, true) then
		options.inline = 1
	end
	
	return mHatnote._hatnote(s, options)
end

p.hatnote = p.hatnoteInline --alias

return p