Module:Sandbox/BrandonXLF/4: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 1:
-- Sandbox, do not delete
local p = {}
 
-- Close <li> and <ul> enclosing deeper itemsdepths
local function closePending(toClose, depth)
local out = ''
while #toClose > 0 and #toClose[#toClose][1] >= #item[1]depth do
out = out .. toClose[#toClose][2]
table.remove(toClose, #toClose)
end
return out
end
 
function p.main(frame)
local wikitext = frame:preprocess(frame.args[1])
local items = {}
local out = ''
-- Parse each row
for indent, item in wikitext:gmatch("(**) *([^\n]+)") do
items[#items + 1] = {'*'#indent ..+ indent1, item}
end
-- List of { depth, closing tag [, rest block-level (for <ul>s) ] }
local toClose = {}
local out = ''
 
-- Bold sublist titles and add a blank list item before them
-- The blank item is used by CSS to make the list item block leel
for i, item in pairs(items) do
out = out .. closePending(toClose, item[21])
-- Close <li> and <ul> enclosing deeper items
while #toClose > 0 and #toClose[#toClose][1] >= #item[1] do
out = out .. toClose[#toClose][2]
table.remove(toClose, #toClose)
end
-- Create a new listslist if needed
whileif #toClose >== 0 and (#toClose[#toClose][1] + 1 < #item[1] or toClose[#toClose][2] ~= '</ul>') dothen
out = out .. '<ul>'
toClose[#toClose + 1] = { item[1]:sub(1, -2) 1, '</ul>', false }
end
Line 33 ⟶ 39:
if keepInline then
out = out .. '<li>' .. item[2]:gsub(' *KEEP%-INLINE$', '') .. '<span class="content-list-inline"> </span>'
elseif toClose[#toClose][3] or i < #items and #items[i + 1][1] > #item[1] then
out = out .. item[2]:gsub(' *KEEP%-INLINE$', '') .. '<span class="content-list-inline"> </span>'
-- Remove ":" if first item is block-level
elseif toClose[#toClose][3] or i < #items and #items[i + 1][1] > #item[1] then
out = out:gsub("&#58; '''''<ul>$", "'''''<ul><ul>")
-- Treat remaining items in this last as block-level
toClose[#toClose][3] = true
out = out .. '<li class="content-sublist">' .. "'''''" .. item[2] .. "&#58; '''''"
elseif toClose[#toClose][3] then
out = out .. '<li class="content-sublist">' .. "'''''" .. item[2] .. "&#58; '''''"
else
out = out .. '<li>' .. item[2]
out = out .. item[2]
end
Line 47 ⟶ 55:
end
out = out .. closePending(toClose, 0)
return '<pre>' .. mw.text.encode(out) .. '</pre>' ..
return '<div class="content-list"><ul>\n' .. out .. '</ul></div>' .. frame:extensionTag{
name = 'templatestyles', args = { src = 'User:BrandonXLF/styles2.css' }
}