https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ASu%2Fsandbox2
Module:Su/sandbox2 - Revision history
2025-05-31T11:36:23Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.3
https://en.wikipedia.org/w/index.php?title=Module:Su/sandbox2&diff=1234374455&oldid=prev
Ahecht: create from Module:Su/sandbox
2024-07-14T01:20:17Z
<p>create from <a href="/wiki/Module:Su/sandbox" title="Module:Su/sandbox">Module:Su/sandbox</a></p>
<p><b>New page</b></p><div>-- This module implements {{su}}.<br />
<br />
local p = {}<br />
<br />
function p.main(frame)<br />
-- Use arguments from the parent frame only, and remove any blank arguments.<br />
-- We don't need to trim whitespace from any arguments, as this module only<br />
-- uses named arguments, and whitespace is trimmed from them automatically. <br />
local origArgs = frame:getParent().args<br />
local args = {}<br />
for k, v in pairs(origArgs) do<br />
if v ~= '' then<br />
args[k] = v<br />
end<br />
end<br />
<br />
-- Define the variables to pass to luaMain.<br />
local sup = args.p<br />
local sub = args.b<br />
local options = {<br />
align = args.a,<br />
fontSize = args.w,<br />
lineHeight = args.lh,<br />
verticalAlign = args.va<br />
}<br />
return p._main(sup, sub, options)<br />
end<br />
<br />
function p.invoke_main(frame)<br />
-- entry point for invocation using frame arguments<br />
<br />
local origArgs = frame.args<br />
local args = {}<br />
for k, v in pairs(origArgs) do<br />
if v ~= '' then<br />
args[k] = v<br />
end<br />
end<br />
<br />
-- Define the variables to pass to luaMain.<br />
local sup = args.p<br />
local sub = args.b<br />
local options = {<br />
align = args.a,<br />
fontSize = args.w,<br />
lineHeight = args.lh,<br />
verticalAlign = args.va<br />
}<br />
return p._main(sup, sub, options)<br />
end<br />
<br />
function p._main(sup, sub, options)<br />
options = options or {}<br />
local span = mw.html.create('span'):addClass('nowrap')<br />
<br />
-- Set the styles.<br />
span:css{<br />
['display'] = 'inline-block',<br />
['margin-bottom'] = '-0.3em',<br />
['vertical-align'] = options.verticalAlign or sub and '-0.4em' or '0.8em',<br />
['line-height'] = options.lineHeight or '1.2em'<br />
}<br />
if options.fontSize == 'f' or options.fontSize == 'fixed' then<br />
span:css{<br />
['font-family'] = 'monospace',<br />
['font-size'] = '80%'<br />
}<br />
else<br />
span:css('font-size', options.fontSize or '80%')<br />
end<br />
if options.align == 'r' or options.align == 'right' then<br />
span:css('text-align', 'right')<br />
elseif options.align == 'c' or options.align == 'center' then<br />
span:css('text-align', 'center')<br />
else<br />
span:css('text-align', 'left')<br />
end<br />
<br />
-- Add the wikitext.<br />
span<br />
:wikitext('&NoBreak;')<br />
:tag('sup')<br />
:css('font-size', 'inherit')<br />
:css('line-height', 'inherit')<br />
:css('vertical-align', 'baseline')<br />
:wikitext(sup)<br />
:done()<br />
:tag('br', {selfClosing = true}):done()<br />
:tag('sub')<br />
:css('font-size', 'inherit')<br />
:css('line-height', 'inherit')<br />
:css('vertical-align', 'baseline')<br />
:wikitext(sub)<br />
:wikitext('&NoBreak;')<br />
<br />
return tostring(span)<br />
end<br />
<br />
return p</div>
Ahecht