Module:Sandbox/RobLa/Foo: Difference between revisions

From Guild of Archivists
(edited for clarity)
 
m (1 revision imported)
 

Latest revision as of 07:26, 30 October 2015

Testing my template: Lua error: bad argument #1 to 'gmatch' (string expected, got nil).


local str = require( 'Module:StringHelper' )
local p = {}

-- generate a bulleted list of section headings extracted from a page.
-- the page is passed as the first argument.
-- example: {{#invoke:Sandbox/RobLa/Foo|captions|Lua scripting/status}}
function p.captions( frame )
    local title = frame.args[1]
    local page = mw.title.new( title )
    local content = page:getContent()
    local captions = ''
    
    for line in str.lines( content ) do
        if str.startswith(line, '== ') and str.endswith(line, ' ==') then
            item = '* ' .. str.strip( line, '= ') .. '\n'
            captions = captions .. item
        end
    end

    return captions
end
 
return p