Modul:Transclude
Vzhled
Transclude může být použit k vložení jedné konkrétní sekce z vybrané stránky. Zatím je povoleno použití pouze mimo hlavní jmenný prostor, pro použití v hlavním jmenném prostoru je třeba získat konsensus pod lípou.
Použití
{{#invoke:Transclude|section|<název stránky>|<název sekce>}}
Alternativně funguje také rozšíření MediaWiki, které umožňuje zobrazit jakoukoliv část stránky, nejenom sekci. Ta ale musí být označená pomocí speciálních značek <section>.
{{#section:<název stránky>|<název sekce>}}
local p = {}
function p.section(context)
local a = require('Modul:Arguments')
local parameters = a.getArgs(context)
-- Get (and parse) a title and a section from the input argument(s)
local title = ""
local section = ""
if parameters[2] then
title = parameters[1]
section = parameters[2]
elseif parameters[1] then
local link = parameters[1]
title = mw.text.split(link, "#")[1]
section = mw.text.split(link, "#")[2]
else
error("Stránka ani sekce nebyla zadána")
end
if not title then
error("Stránka nebyla zadána")
elseif not section then
error("Sekce nebyla zadána")
end
-- Find a page and get its content if any
local page = mw.title.new(title)
local text = page:getContent()
if not text then
error("Stránka nebyla nalezena")
end
-- Get a position of the section in the page
local heading = nil
local content = nil
local level = ""
heading, content, level = string.find(text, "\n(==+) *" .. section .. " *%1 *\n")
if not heading then
error("Sekce nebyla nalezena")
end
-- Get a position of a next section if any
local next_heading = string.find(text, "\n" .. level .. " *[^\n=]* *" .. level .. " *\n", content)
-- Print output
return string.sub(text, heading, next_heading or string.len(text))
end
return p