Content deleted Content added
Improve comments; minor bug fix (parsing Image:... within paragraph) |
Make the bold title near the start of the article into a wikilink to the article |
||
Line 111:
local redir = mRedirect.getTarget(title)
if redir then title = mw.title.new(redir) end
pagename = redir or pagename
text = title:getContent()
Line 202 ⟶ 203:
until not text or text == "" or not token or token == "" -- loop until all text parsed
text = mw.ustring.gsub(t, "\n+$", "") -- remove
-- replace the bold title or synonym near the start of the article by a wikilink to the article
local lang = mw.language.getContentLanguage()
local pos = mw.ustring.find(text, "'''" .. lang:ucfirst(pagename) .. "'''", 1, true) -- look for "'''Foo''' is..." (uc) or "A '''foo''' is..." (lc)
or mw.ustring.find(text, "'''" .. lang:lcfirst(pagename) .. "'''", 1, true) -- plain search: special characters in pagename represent themselves
if pos then
local len = mw.ustring.len(pagename)
text = mw.ustring.sub(text, 1, pos + 2) .. "[[" .. mw.ustring.sub(text, pos + 3, pos + len + 2) .. "]]" .. mw.ustring.sub(text, pos + len + 3, -1) -- link it
else -- look for anything unlinked in bold, assumed to be a synonym of the title (e.g. a person's birth name)
text = mw.ustring.gsub(text, "(.-'''+)(.-)'''", function(a, b) -- replace '''Foo''' by '''[[pagename|Foo]] if early in article and not wikilinked
if mw.ustring.len(a) < 100 and not mw.ustring.find(b, "%[") then return a .. "[[" .. pagename .. "|" .. b .. "]]'''" else return nil end
end, 1)
end
if options.more then text = text .. " '''[[" .. pagename .. "|" .. options.more .. "]]'''" end -- wikilink to article for more info
return text
end
|