Jump to content

Module:Sandbox/BrandonXLF/4

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BrandonXLF (talk | contribs) at 07:29, 18 April 2024 (Support Parsoid). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- Sandbox, do not delete
local p = {}

function p.main(frame)
	local wikitext = frame:preprocess(frame.args[1])
	local items = {}
	
	-- Parse each row
	for indent, item in wikitext:gmatch("(**) *([^\n]+)") do  
	    items[#items + 1] = {'*' .. indent, item}
	end
	
	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  
		-- 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 new lists
		while #toClose > 0 and (#toClose[#toClose][1] + 1 < #item[1] or toClose[#toClose][2] ~= '</ul>') do
			out = out .. '<ul>'
			toClose[#toClose + 1] = { item[1]:sub(1, -2), '</ul>' }
		end
		
		-- Added by {{Keep inline}}
		local keepInline = item[2]:match('KEEP%-INLINE$') ~= nil
		
		if keepInline then
			out = out .. '<li>'
			out = out .. item[2]:gsub(' *KEEP%-INLINE$', '') .. '<span class="content-list-inline"></span>'
		elseif i < #items and #items[i + 1][1] > #item[1] then
			out = out .. '<li class="content-sublist">'
			out = out .. "'''''" .. item[2] .. "&#58;'''''"
		else
			out = out .. '<li>'
			out = out .. item[2]
		end
		
		toClose[#toClose + 1] = { item[1], '</li>' }
	end
	
	return '<pre>' .. mw.text.encode(out) .. '</pre>' ..
	
	'<div class="content-list"><ul>\n' .. out  .. '</ul></div>' .. frame:extensionTag{
		name = 'templatestyles', args = { src = 'User:BrandonXLF/styles2.css' }
	}
end

return p