Content deleted Content added
No edit summary |
No edit summary |
||
Line 11:
frame: frame object required to preprocess template_name
article_title: the name of the article to inspect - correct spelling and captialization is required
returns two values:
on success, returns the short description text
on failure, returns error message and nil
]]
--local function extract_from_template (frame, article_title,
local function extract_from_template (frame, article_title, template_names_tbl)
local content = mw.title.new (article_title):getContent(); -- read the unparsed article source
if not content then
return '<span style="font-size:100%;" class="error">error: no article: ' .. article_title .. '</span>';
end
local template_name_pattern;
local start
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] break; -- found a matching template
end
end
if not start then -- no templates found: return name of first template in template_names_tbl in error message
▲ local start = string.find (content, '{{%s*' .. template_name_pattern); -- find the start of {{template name ...;
return '<span style="font-size:100%;" class="error">error: no template: ' ..
▲ if not start then
▲ return '<span style="font-size:100%;" class="error">error: no template: ' .. template_name .. ' in: ' .. article_title .. '</span>';
end
Line 43 ⟶ 54:
end
return
-- preprocess the template then apply syntax highlighting
-- this will display the preprocessed template; not usable here
Line 130 ⟶ 141:
return extract_from_article (article_title);
end
end
-----test-----
-- temporary test function to be deleted
local function test (frame)
local tbl = {'Infobox television episode/sandbox', 'short description'};
local text, good = extract_from_template (frame, 'User:Trappist the monk/sandbox', tbl);
if good then
return text;
else
return 'extract_from_template() returned this: ' .. text
end
end
Line 139 ⟶ 164:
extract_short_description = extract_short_description,
extract_from_template = extract_from_template,
extract_from_article = extract_from_article,
test = test, -- to be deleted
}
|