Open main menu

Difference between revisions of "Module:Hatnote inline"

m (1 revision imported)
m (1 revision imported)
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
 
--                              Module:Hatnote-inline                        --
 
--                              Module:Hatnote-inline                        --
 
--                                                                            --
 
--                                                                            --
-- This module produces hatnote-style links and links to related articles,   --
+
-- This module produces hatnote-style links, and links to related articles,   --
 
-- but inside a <span>, instead of the <div> used by Module:Hatnote.  It      --
 
-- but inside a <span>, instead of the <div> used by Module:Hatnote.  It      --
 
-- implements the {{hatnote-inline}} meta-template.                          --
 
-- implements the {{hatnote-inline}} meta-template.                          --
Line 17: Line 17:
 
if args.inline == nil or yesno(args.inline, true) then
 
if args.inline == nil or yesno(args.inline, true) then
 
local subs = {
 
local subs = {
['^<div'] = '<span',
+
['<div'] = '<span',
 
['</div>$'] = '</span>'
 
['</div>$'] = '</span>'
 
}
 
}
for k, v in pairs(subs) do hatnote = string.gsub(hatnote, k, v) 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 18:23, 6 December 2021

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