模块:Outdent:修订间差异
来自RIA | Wiki
更多操作
简化 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local yesno = require('Module:Yesno') | |||
function p.outdent(frame) | function p.outdent(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local width = 0 | local width = 0 | ||
local reversed = args['reverse'] or args['indent'] or args['r'] or args['in'] -- aliases for reverse | local reversed = args['reverse'] or args['indent'] or args['r'] or args['in'] -- aliases for reverse | ||
local reversed = yesno(reversed) | |||
if not args[1] then args[1] = '' end -- un-nil args[1] | if not args[1] then args[1] = '' end -- un-nil args[1] | ||
width = width + select(2, string.gsub(args[1],':','')) -- increase by 1 for every : | width = width + select(2, string.gsub(args[1],':','')) -- increase by 1 for every : | ||
width = width + select(2, string.gsub(args[1],'*','')) -- increase by 1 for every * | width = width + select(2, string.gsub(args[1],'*','')) -- increase by 1 for every * | ||
width = width + select(2, string.gsub(args[1],'#','')) * 2 -- increase by 2 for every # | width = width + select(2, string.gsub(args[1],'#','')) * 2 -- increase by 2 for every # | ||
if width == 0 then width = tonumber(args[1]) end -- set width to args[1] if needed | if width == 0 then width = tonumber(args[1]) end -- set width to args[1] if needed | ||
| 第22行: | 第24行: | ||
end | end | ||
if width > 40 then width = 40 end -- max width | if width > 40 then width = 40 end -- max width | ||
width = width * 1.6 -- set width to proper width | width = width * 1.6 -- set width to proper width | ||
local note = (args['note'] or args[2]) and '([[wikipedia:Wikipedia:Indentation#Outdenting|外缩进]])' or '' -- note | local note = (args['note'] or args[2]) and '([[wikipedia:Wikipedia:Indentation#Outdenting|外缩进]])' or '' -- note | ||
2023年8月14日 (一) 23:45的版本
此模块的文档可以在模块:Outdent/doc创建
local p = {}
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
function p.outdent(frame)
local args = getArgs(frame)
local width = 0
local reversed = args['reverse'] or args['indent'] or args['r'] or args['in'] -- aliases for reverse
local reversed = yesno(reversed)
if not args[1] then args[1] = '' end -- un-nil args[1]
width = width + select(2, string.gsub(args[1],':','')) -- increase by 1 for every :
width = width + select(2, string.gsub(args[1],'*','')) -- increase by 1 for every *
width = width + select(2, string.gsub(args[1],'#','')) * 2 -- increase by 2 for every #
if width == 0 then width = tonumber(args[1]) end -- set width to args[1] if needed
if not width then width = 10 end -- default width
if width < 0
then
width = -width
reversed = not reversed
end
if width > 40 then width = 40 end -- max width
width = width * 1.6 -- set width to proper width
local note = (args['note'] or args[2]) and '([[wikipedia:Wikipedia:Indentation#Outdenting|外缩进]])' or '' -- note
local templatestyles = mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = 'Module:Outdent/styles.css' }
}
return templatestyles .. '<div class="template-outdent' .. ((reversed and ' reversed') or '') .. '" style="width: ' .. width .. 'em"><div class="template-outdent-line"></div></div>' .. note
end
return p