9,921
editsImprove output of htmlList style.
No edit summary |
(Improve output of htmlList style.) |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 10: | Line 10: | ||
local useTemplateOnElements | local useTemplateOnElements | ||
local useTwoArgTemplateOnElements | local useTwoArgTemplateOnElements | ||
local | local textDelim | ||
local textLastDelim | |||
local function splitListString(listString) | local function splitListString(listString) | ||
local strings = {} | |||
for str in listString:gmatch("[^" .. listDelimiters .. "]+") do | |||
table.insert(strings, str:match("^%s*(.-)%s*$")) | |||
end | |||
return strings | |||
end | end | ||
Line 166: | Line 167: | ||
end | end | ||
-- These functions implement | -- These functions implement different output styles. The elements will have | ||
-- already gone through processElement() at this point, so they only need to be | -- already gone through processElement() at this point, so they only need to be | ||
-- glued together to produce the desired | -- glued together to produce the desired style of listing format. | ||
local converters = { | local converters = { | ||
text = function (elements) | |||
local result = "" | |||
local count = #elements | |||
for i, str in ipairs(elements) do | for i, str in ipairs(elements) do | ||
if i < count then | if i == 1 then | ||
result = result .. | result = str | ||
elseif i < count then | |||
result = result .. textDelim .. str | |||
else | else | ||
result = result .. | result = result .. textLastDelim .. str | ||
end | end | ||
end | |||
return result | |||
end, | end, | ||
htmlList = function (elements) | htmlList = function (elements) | ||
local result = "" | local result = "<ul>\n" | ||
for i, str in ipairs(elements) do | |||
result = result .. "<li>" .. str .. "</li>\n" | |||
end | |||
return result .. "</ul>" | |||
end, | |||
tableList = function (elements) | |||
local result = "<div class=\"bg3wiki-tablelist\">" | |||
for i, str in ipairs(elements) do | |||
result = result .. str .. "\n" | |||
end | |||
return result .. "</div>" | |||
end, | |||
htmlListNoBullets = function (elements) | |||
local result = "<ul style='list-style: none; margin: 0;'>\n" | |||
for i, str in ipairs(elements) do | for i, str in ipairs(elements) do | ||
result = result .. " | result = result .. "<li>" .. str .. "</li>\n" | ||
end | end | ||
return result | return result .. "</ul>" | ||
end, | end, | ||
simpleList = function (elements) | simpleList = function (elements) | ||
Line 226: | Line 236: | ||
useTemplateOnElements = args['useTemplate'] | useTemplateOnElements = args['useTemplate'] | ||
useTwoArgTemplateOnElements = args['useTemplate2'] | useTwoArgTemplateOnElements = args['useTemplate2'] | ||
textDelim = args['textDelim'] | |||
if textDelim then | |||
textLastDelim = args['textLastDelim'] or textDelim | |||
else | |||
textDelim = ', ' | |||
textLastDelim = args['textLastDelim'] or ', and ' | |||
end | |||
local | local style = args['style'] or args['type'] or 'text' | ||
local converter = converters[ | local converter = converters[style] | ||
local elements = {} | local elements = {} | ||
local listString = args[1] | local listString = args[1] |