Difference between revisions of "Module:Extract short description"
Jump to navigation
Jump to search
blackwiki>Trappist the monk |
blackwiki>Trappist the monk |
||
| Line 1: | Line 1: | ||
| + | require('Module:No globals'); | ||
| + | |||
local function tag (frame) | local function tag (frame) | ||
local content = mw.title.new (frame.args[1]):getContent() | local content = mw.title.new (frame.args[1]):getContent() | ||
| − | local ibox_start = string.find (content, '{{%s*' .. 'Infobox television episode/sandbox') | + | local ibox_start = string.find (content, '{{%s*' .. 'Infobox television episode/sandbox') -- find the start of {{Infobox ...; ibox_name is a pattern that accepts various legit spacing and capitalization ... |
if not ibox_start then | if not ibox_start then | ||
return 'Infobox television episode/sandbox not found' | return 'Infobox television episode/sandbox not found' | ||
| Line 13: | Line 15: | ||
local template_name = 'Infobox television episode/sandbox' | local template_name = 'Infobox television episode/sandbox' | ||
local template_content = ibox_text:gsub ('{{%s' .. template_name, ''):gsub ('}}$', '') | local template_content = ibox_text:gsub ('{{%s' .. template_name, ''):gsub ('}}$', '') | ||
| − | -- preprocess the template then apply syntax highlighting | + | -- preprocess the template then apply syntax highlighting |
return frame:callParserFunction ('#tag:syntaxhighlight', frame:expandTemplate ({title=template_name, args = {template_content}})); | return frame:callParserFunction ('#tag:syntaxhighlight', frame:expandTemplate ({title=template_name, args = {template_content}})); | ||
end | end | ||
return {tag = tag} | return {tag = tag} | ||
Revision as of 18:25, 27 September 2018
Documentation for this module may be created at Module:Extract short description/doc
require('Module:No globals');
local function tag (frame)
local content = mw.title.new (frame.args[1]):getContent()
local ibox_start = string.find (content, '{{%s*' .. 'Infobox television episode/sandbox') -- find the start of {{Infobox ...; ibox_name is a pattern that accepts various legit spacing and capitalization ...
if not ibox_start then
return 'Infobox television episode/sandbox not found'
end
local ibox_text = string.match (content, '%b{}', ibox_start) -- ibox_start points to first { of the infobox template
if not ibox_text then
return 'failed to extract Infobox television episode/sandbox'
end
local template_name = 'Infobox television episode/sandbox'
local template_content = ibox_text:gsub ('{{%s' .. template_name, ''):gsub ('}}$', '')
-- preprocess the template then apply syntax highlighting
return frame:callParserFunction ('#tag:syntaxhighlight', frame:expandTemplate ({title=template_name, args = {template_content}}));
end
return {tag = tag}