Difference between revisions of "Module:Sandbox/RobLa/Foo"

From Northumberland Climbing
Jump to navigation Jump to search
module>ATDT
(edited for clarity)
 
m (1 revision imported)
 
(No difference)

Latest revision as of 05:51, 31 July 2020

Testing my template:

  • 2011-08-31
  • 2011-09-30
  • 2011-10-31
  • 2012-01-26
  • 2012-01-31
  • 2012-04-05
  • 2012-04-19
  • 2012-04-monthly
  • 2012-05-10
  • 2012-05-monthly
  • 2012-06-18
  • 2012-06-monthly
  • 2012-07-monthly
  • 2012-08-monthly
  • 2012-09-06
  • 2012-09-monthly
  • 2012-10-18
  • 2012-11-20
  • 2012-11-monthly
  • 2013-01-monthly
  • 2013-02-monthly
  • 2013-03-monthly
  • 2013-04-monthly

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