Modul:ExtractHeadings

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Die Dokumentation für dieses Modul kann unter Modul:ExtractHeadings/Doku erstellt werden

local p = {}
local getArgs = require('Module:Arguments').getArgs
local mwTitle = mw.title
local mwUri = mw.uri

local function stripMarkup(text)
    linksRemoved = text:gsub('%[%[[^|%]]+%|', ''):gsub('%[%[', ''):gsub('%]%]', '')
    markupRemoved = linksRemoved:gsub("''+", '')
    return markupRemoved
end

function p.extractHeadings(frame)
    local args = getArgs(frame)
    local title = args[1]
    local page = mwTitle.new(title)
    local content = page:getContent()
    
    local headings = {}
    for heading in content:gmatch('==+%s*([^=]+)%s*==+') do
        local cleanHeading = stripMarkup(heading)
        local link = title .. '#' .. mwUri.anchorEncode(cleanHeading)
        table.insert(headings, '* [[' .. link .. '|' .. cleanHeading .. ']]')
    end
    
    return table.concat(headings, '\n')
end

return p