Module:Listing: Difference between revisions

Want an adless experience? Log in or Create an account.
instead of parsing raw content and then expanding some templates within the content, just expand the whole content as a template
(be a little smarter about parsing transclusion args (still not handling named args, haven't needed those yet))
(instead of parsing raw content and then expanding some templates within the content, just expand the whole content as a template)
Line 25: Line 25:


function handleLine( line, currentSection )
function handleLine( line, currentSection )
  line = line:gsub( '{{{.-|}}}', '' ) -- can appear on listings that are transcluded into other listings, but are only relevant to those other listings
  -- recurse on transclusion
  local transclusion = line:match( '^{{:(.-)}}$' )
  if transclusion then
    local transclusionParts = mw.text.split( transclusion, '|' )
    local transcludedTitle = table.remove( transclusionParts, 1 ) -- remainder is treated as anonymous (numbered) args - TODO handle named args
    local transcludedContent = mw.text.killMarkers( mw.getCurrentFrame():expandTemplate{ title = ':' .. transcludedTitle, args = transclusionParts } )
    for transcludedLine in gsplit( transcludedContent, '\n' ) do
      currentSection = handleLine( transcludedLine, currentSection )
    end
    return currentSection
  end
   local headingLevel, headingText = string.match( line, '^%s*(=+)%s*(.-)%s*=+$' )
   local headingLevel, headingText = string.match( line, '^%s*(=+)%s*(.-)%s*=+$' )
   if headingLevel then -- line is a heading
   if headingLevel then -- line is a heading
Line 91: Line 77:


function p._parseListing( pageName, pageContent )
function p._parseListing( pageName, pageContent )
   local pageContent = pageContent or mw.title.new( pageName ):getContent()
   local pageContent = pageContent or mw.text.killMarkers( mw.getCurrentFrame():expandTemplate{ title = ':' .. pageName, args = {} } )
   local root = {
   local root = {
     level = 1,
     level = 1,