Module:Sidebar: Difference between revisions
Appearance
apply automatic newlines |
correct handling of automatic newlines |
||
Line 8: | Line 8: | ||
local Navbar = require('Module:Navbar') | local Navbar = require('Module:Navbar') | ||
local function trimAndAddAutomaticNewline(s) | |||
-- For compatibility with the original {{sidebar with collapsible lists}} | |||
-- implementation, which passed some parameters through {{#if}} to trim | |||
-- their whitespace. This also triggered the automatic newline behavior. | |||
-- ([[meta:Help:Newlines and spaces#Automatic newline]]) | |||
s = mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1") | |||
if mw.ustring.find(s, '^[#*:;]') or mw.ustring.find(s, '^{|') then | |||
return '\n' .. s | |||
else | |||
return s | |||
end | |||
end | |||
local function _sidebar(args) | local function _sidebar(args) | ||
local root = HtmlBuilder.create('table') | local root = HtmlBuilder.create('table') | ||
Line 221: | Line 234: | ||
.cssText(args.listtitlestyle) | .cssText(args.listtitlestyle) | ||
.cssText(args['list' .. num .. 'titlestyle']) | .cssText(args['list' .. num .. 'titlestyle']) | ||
.wikitext(args['list' .. num .. 'title'] or 'List') | .wikitext(trimAndAddAutomaticNewline(args['list' .. num .. 'title'] or 'List')) | ||
.done() | .done() | ||
.tag('div') | .tag('div') | ||
Line 232: | Line 245: | ||
.cssText(args.liststyle) | .cssText(args.liststyle) | ||
.cssText(args['list' .. num .. 'style']) | .cssText(args['list' .. num .. 'style']) | ||
.wikitext(args['list' .. num]) | .wikitext(trimAndAddAutomaticNewline(args['list' .. num])) | ||
contentArgs['content' .. num] = tostring(row) | contentArgs['content' .. num] = tostring(row) | ||
Line 268: | Line 281: | ||
for k, v in pairs(origArgs) do | for k, v in pairs(origArgs) do | ||
if v ~= '' then | if v ~= '' then | ||
args[k] = v | args[k] = v | ||
end | end |