diff options
author | madmaxoft <github@xoft.cz> | 2013-10-15 18:42:33 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-10-15 18:44:13 +0200 |
commit | c9a9a30fa54f2c41290ba4a99e3575ad3f5373f8 (patch) | |
tree | 8c72704641fc5e24bcc7d9700b87359fde4bdcf6 /MCServer | |
parent | Merge pull request #258 from tonibm19/patch-2 (diff) | |
download | cuberite-c9a9a30fa54f2c41290ba4a99e3575ad3f5373f8.tar cuberite-c9a9a30fa54f2c41290ba4a99e3575ad3f5373f8.tar.gz cuberite-c9a9a30fa54f2c41290ba4a99e3575ad3f5373f8.tar.bz2 cuberite-c9a9a30fa54f2c41290ba4a99e3575ad3f5373f8.tar.lz cuberite-c9a9a30fa54f2c41290ba4a99e3575ad3f5373f8.tar.xz cuberite-c9a9a30fa54f2c41290ba4a99e3575ad3f5373f8.tar.zst cuberite-c9a9a30fa54f2c41290ba4a99e3575ad3f5373f8.zip |
Diffstat (limited to 'MCServer')
-rw-r--r-- | MCServer/Plugins/APIDump/main.lua | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/MCServer/Plugins/APIDump/main.lua b/MCServer/Plugins/APIDump/main.lua index 6ae4a6b0f..163c505b2 100644 --- a/MCServer/Plugins/APIDump/main.lua +++ b/MCServer/Plugins/APIDump/main.lua @@ -617,8 +617,39 @@ end -- Make a link out of anything with the special linkifying syntax {{link|title}} function LinkifyString(a_String) - local txt = a_String:gsub("{{([^|}]*)|([^}]*)}}", "<a href=\"%1.html\">%2</a>") -- {{link|title}} - txt = txt:gsub("{{([^|}]*)}}", "<a href=\"%1.html\">%1</a>") -- {{LinkAndTitle}} + local function CreateLink(Link, Title) + 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; end |