Changes

Jump to navigation Jump to search
1,138 bytes removed ,  23:33, 30 November 2019
m
1 revision imported
Line 1: Line 1:  
-- This module implements {{section link}}.
 
-- This module implements {{section link}}.
require('Module:No globals');
      
local checkType = require('libraryUtil').checkType
 
local checkType = require('libraryUtil').checkType
Line 10: Line 9:  
page = page or ''
 
page = page or ''
 
return string.format('[[%s#%s|%s]]', page, section, display)
 
return string.format('[[%s#%s|%s]]', page, section, display)
end
  −
  −
local function normalizeTitle(title)
  −
title = mw.ustring.gsub(mw.ustring.gsub(title, "'", ""), '"', '')
  −
title = mw.ustring.gsub(title, "%b<>", "")
  −
return mw.title.new(title).prefixedText
   
end
 
end
   Line 47: Line 40:  
local linkPage = page or ''
 
local linkPage = page or ''
 
local section = sections[1] or 'Notes'
 
local section = sections[1] or 'Notes'
local display = '§&nbsp;' .. section
+
local display = '§&thinsp;' .. section
 
if isShowingPage then
 
if isShowingPage then
 
page = page or title.prefixedText
 
page = page or title.prefixedText
if options.display and options.display ~= '' then
+
display = page .. ' ' .. display
if normalizeTitle(options.display) == normalizeTitle(page) then
  −
display = options.display .. ' ' .. display
  −
else
  −
error(string.format(
  −
'Display title "%s" was ignored since it is ' ..
  −
"not equivalent to the page's actual title",
  −
options.display
  −
), 0)
  −
end
  −
else
  −
display = page .. ' ' .. display
  −
end
   
end
 
end
 
return makeSectionLink(linkPage, section, display)
 
return makeSectionLink(linkPage, section, display)
Line 85: Line 66:     
-- Add the intro text.
 
-- Add the intro text.
local intro = '§§&nbsp;'
+
local intro = '§§&thinsp;'
 
if isShowingPage then
 
if isShowingPage then
 
intro = (page or title.prefixedText) .. ' ' .. intro
 
intro = (page or title.prefixedText) .. ' ' .. intro
Line 96: Line 77:     
function p.main(frame)
 
function p.main(frame)
local yesno = require('Module:Yesno')
   
local args = require('Module:Arguments').getArgs(frame, {
 
local args = require('Module:Arguments').getArgs(frame, {
 
wrappers = 'Template:Section link',
 
wrappers = 'Template:Section link',
Line 107: Line 87:  
end
 
end
 
})
 
})
  −
for k, v in pairs(args) do -- replace underscores in the positional parameter values
  −
if 'number' == type(k) and not yesno (args['keep-underscores']) then -- unless |keep-underscores=yes
  −
args[k] = v:gsub ('_', ' ') -- do the replacement
  −
end
  −
end
      
-- Sort the arguments.
 
-- Sort the arguments.
Line 121: Line 95:  
-- Doing this in the loop because of a bug in [[Module:Arguments]]
 
-- Doing this in the loop because of a bug in [[Module:Arguments]]
 
-- when using pairs with deleted arguments.
 
-- when using pairs with deleted arguments.
page = mw.text.decode(v, true)
+
page = v
 
elseif type(k) == 'number' then
 
elseif type(k) == 'number' then
 
sections[k] = v
 
sections[k] = v
Line 127: Line 101:  
options[k] = v
 
options[k] = v
 
end
 
end
end
  −
  −
options.nopage = yesno (options.nopage); -- make boolean
  −
  −
-- Extract section from page, if present
  −
if page then
  −
local p, s = page:match('^(.-)#(.*)$')
  −
if p then page, sections[1] = p, s end
   
end
 
end
  
4,000

edits

Navigation menu