Modul:Sidebar: Unterschied zwischen den Versionen
correct handling of automatic newlines
imported>Toohool (apply automatic newlines) |
imported>Toohool (correct handling of automatic newlines) |
||
| Zeile 8: | Zeile 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') | ||
| Zeile 221: | Zeile 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') | ||
| Zeile 232: | Zeile 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) | ||
| Zeile 268: | Zeile 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 | ||