17,273
edits
(add ^...$ to heading regex) |
(comment out some things to try to reduce cpu usage... this doesn't seem like it should be so expensive though) |
||
Line 3: | Line 3: | ||
function p._parseListing( pageName ) | function p._parseListing( pageName ) | ||
local pageContent = mw.title.new( pageName ):getContent() | local pageContent = mw.title.new( pageName ):getContent() | ||
local | local root = { | ||
level = 1, | level = 1, | ||
name = pageName, | name = pageName, | ||
Line 10: | Line 10: | ||
sections = {} | sections = {} | ||
} | } | ||
local currentSection = root | |||
-- can't think of a regex to split sections so go line by line | -- can't think of a regex to split sections so go line by line | ||
Line 31: | Line 32: | ||
currentSection = newSection | currentSection = newSection | ||
elseif #currentSection.sections == 0 then -- no child headings yet so this is part of the summary of the current section | elseif #currentSection.sections == 0 then -- no child headings yet so this is part of the summary of the current section | ||
-- currentSection.summary = currentSection.summary .. line .. '\n' | |||
end | end | ||
-- add to content of all parent sections, plus current section if line isn't a heading | -- add to content of all parent sections, plus current section if line isn't a heading | ||
-- content currently isn't needed so disabling this for perf | |||
-- local contentBackfillSection = headingLevel and currentSection.parent or currentSection | |||
-- repeat | |||
-- contentBackfillSection.content = contentBackfillSection.content .. line .. '\n' | |||
-- contentBackfillSection = contentBackfillSection.parent | |||
-- until not contentBackfillSection | |||
end | end | ||
return root | |||
end | end | ||