Content deleted Content added
No edit summary |
No edit summary |
||
Line 9:
requires three arguments:
frame: frame object required
article_title: the name of the article to inspect - correct spelling and captialization is required
template: the name without namespace of the template to inspect -
on success, returns the short description text; error message else
Line 18:
local function extract_from_template (frame, article_title, template_name)
local content = mw.title.new (article_title):getContent(); -- read the unparsed article source
local template_name_pattern = template_name:gsub ('^%a', string.lower):gsub ('^%a', '%[%1%1%]'):gsub ('%[%a', string.upper); -- make lua pattern for initial letter upper or lower case: A -> [Aa]
Line 26:
end
local
if not
return '<span style="font-size:100%;" class="error">error: failed to extract template: ' .. template_name .. '</span>';
end
text = frame:preprocess (text):match ('<div[^>]-class="shortdescription.->(.+)</div>'); -- preprocess and extract shortdescription text▼
▲ text = text:match ('<div[^>]-class="shortdescription.->(.+)</div>'); -- extract shortdescription text
if not text then
Line 40 ⟶ 39:
return text and mw.text.trim (text); -- trim whitespace and done
-- preprocess the template then apply syntax highlighting
-- this will display the
-- for much other than debugging because syntaxhighlight returns a stripmarker
-- return frame:callParserFunction ('#tag:syntaxhighlight', frame:preprocess (template_text));
end
Line 54 ⟶ 53:
long name controls; if multiples of the same name are present, the first-found controls.
requires one argument: article_title is the name
on success, returns the short description text; error message else
Line 72 ⟶ 71:
text = content:match ('%b{}', start); -- get the short description template; start points to first { of the template
if not text then
text = text:match ('^[^|}]+|%s*(.+)%s*}}$'); -- strip '{{template name| and }}; trim leading and trailing whitespace▼
return '<span style="font-size:100%;" class="error">error: failed to extract short description template from ' .. article_title .. '</span>';
end
▲ text = text:match ('^[^|}]+|%s*(.+)%s*}}$'); -- strip '{{template name|' and '}}'; trim leading and trailing whitespace
return text and text or '<span style="font-size:100%;" class="error">error: no short description text in: ' .. article_title .. '</span>';
Line 88 ⟶ 91:
named template.
This template entry
{{{1}}} or |article=: required; name of wiki article from which to extract the short description
{{{2}}} or |template=; optional; name of template that holds the {{short description}} template
Line 99 ⟶ 102:
local getArgs = require('Module:Arguments').getArgs;
local args = getArgs(frame);
if args[1] and args.article then -- both assigned, fail with an error message
return '<span style="font-size:100%;" class="error">error: conflicting |{{{1}}} and |article= parameters</span>';
end
local article_title = args[1] or args.article; -- the required parameter
|