Module:Section link: Difference between revisions

    m>Ahecht
    (Detect anchors in page parameter, other code cleanup)
    m>Ahecht
    (cleanup code)
    Line 16: Line 16:
    end
    end


    function p._main(page, sections, options, title, displaytitle)
    function p._main(page, sections, options, title)
    -- Validate input.
    -- Validate input.
    checkType('_main', 1, page, 'string', true)
    checkType('_main', 1, page, 'string', true)
    Line 48: Line 48:
    if isShowingPage then
    if isShowingPage then
    page = page or title.prefixedText
    page = page or title.prefixedText
    if displaytitle and displaytitle ~= '' then
    if options.display and options.display ~= '' then
    if normalizeTitle(displaytitle) == normalizeTitle(page) then
    if normalizeTitle(options.display) == normalizeTitle(page) then
    display = displaytitle .. ' ' .. display
    display = options.display .. ' ' .. display
    else
    else
    error(string.format(
    error(string.format(
    'Display title "%s" was ignored since it is ' ..
    'Display title "%s" was ignored since it is ' ..
    "not equivalent to the page's actual title",
    "not equivalent to the page's actual title",
    displaytitle
    options.display
    ), 0)
    ), 0)
    end
    end
    Line 106: Line 106:


    -- Sort the arguments.
    -- Sort the arguments.
    local page, displaytitle
    local page
    local sections, options = {}, {}
    local sections, options = {}, {}
    for k, v in pairs(args) do
    for k, v in pairs(args) do
    Line 115: Line 115:
    elseif type(k) == 'number' then
    elseif type(k) == 'number' then
    sections[k] = v
    sections[k] = v
    elseif k == 'display' then
    displaytitle = v
    else
    else
    options[k] = v
    options[k] = v
    Line 142: Line 140:
    sections = compressArray(sections)
    sections = compressArray(sections)


    return p._main(page, sections, options, nil, displaytitle)
    return p._main(page, sections, options)
    end
    end


    return p
    return p