parent
9376005778
commit
c9a9a30fa5
@ -617,8 +617,39 @@ end
|
|||||||
|
|
||||||
-- Make a link out of anything with the special linkifying syntax {{link|title}}
|
-- Make a link out of anything with the special linkifying syntax {{link|title}}
|
||||||
function LinkifyString(a_String)
|
function LinkifyString(a_String)
|
||||||
local txt = a_String:gsub("{{([^|}]*)|([^}]*)}}", "<a href=\"%1.html\">%2</a>") -- {{link|title}}
|
local function CreateLink(Link, Title)
|
||||||
txt = txt:gsub("{{([^|}]*)}}", "<a href=\"%1.html\">%1</a>") -- {{LinkAndTitle}}
|
if (Link:sub(1, 7) == "http://") then
|
||||||
|
-- The link is a full absolute URL, do not modify, do not track:
|
||||||
|
return "<a href=\"" .. Link .. "\">" .. Title .. "</a>";
|
||||||
|
end
|
||||||
|
local idxHash = Link:find("#");
|
||||||
|
if (idxHash ~= nil) then
|
||||||
|
-- The link contains an anchor:
|
||||||
|
if (idxHash == 1) then
|
||||||
|
-- Anchor in the current page, no need to track:
|
||||||
|
return "<a href=\"" .. Link .. "\">" .. Title .. "</a>";
|
||||||
|
end
|
||||||
|
-- Anchor in another page:
|
||||||
|
-- TODO: track this link
|
||||||
|
return "<a href=\"" .. Link:sub(1, idxHash - 1) .. ".html#" .. Link:sub(idxHash + 1) .. "\">" .. Title .. "</a>";
|
||||||
|
end
|
||||||
|
-- Link without anchor:
|
||||||
|
-- TODO; track this link
|
||||||
|
return "<a href=\"" .. Link .. ".html\">" .. Title .. "</a>";
|
||||||
|
end
|
||||||
|
|
||||||
|
local txt = a_String:gsub("{{([^|}]*)|([^}]*)}}", CreateLink) -- {{link|title}}
|
||||||
|
|
||||||
|
txt = txt:gsub("{{([^|}]*)}}", -- {{LinkAndTitle}}
|
||||||
|
function(LinkAndTitle)
|
||||||
|
local idxHash = LinkAndTitle:find("#");
|
||||||
|
if (idxHash ~= nil) then
|
||||||
|
-- The LinkAndTitle contains a hash, remove the hashed part from the title:
|
||||||
|
return CreateLink(LinkAndTitle, LinkAndTitle:sub(1, idxHash - 1));
|
||||||
|
end
|
||||||
|
return CreateLink(LinkAndTitle, LinkAndTitle);
|
||||||
|
end
|
||||||
|
);
|
||||||
return txt;
|
return txt;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user