Module:UtilsMarkup: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search
(+ support for file and category links)
(Splitoff UtilsMarkup/Link, added wikitable as a submodule)
Line 2: Line 2:
local h = {}
local h = {}


local utilsDPL = require("Module:UtilsDPL")
p.link = require("Module:UtilsMarkup/Link").link
 
p.wikitable = require("Module:UtilsMarkup/Wikitable").wikitable
-- If backlink == false then this print an external link that looks like an internal one
p.tabbedWikitable = require("Module:UtilsMarkup/Wikitable").tabbedWikitable
-- (useful for creating links that do not appear in Special:WhatLinksHere)
function p.link(link, text, backlink)
if not link then
return ""
end
link = mw.text.trim(link)
if link:find('http') then
return h.externalLink(link, text)
end
if backlink == false then
local pageExists = utilsDPL.pageExists(link)
local url = tostring(mw.uri.fullUrl(link, {
action = not pageExists and "edit" or nil,
redlink = not pageExists and "1" or nil
}))
local externalLink = h.externalLink(url, text or link)
local formattedLink = p.format(externalLink, {
class = pageExists and "plainlinks" or "plainlinks new"
})
return formattedLink
end
local title = mw.title.new(link)
if title.nsText == "File" or title.nsText == "Category" then
link = ":" .. link
if text == "" then
text = title.text
end
end
return h.internalLink(link, text)
end
 
function h.internalLink(page, display)
if not page then
return ""
end
if not display then
return ("[[%s]]"):format(page)
end
return ('[[%s|%s]]'):format(page, display)
end
 
function h.externalLink(page, display)
if not page then
return ""
end
if not display then
return page
end
return ('[%s %s]'):format(page, display)
end


function p.format(text, args)
function p.format(text, args)

Revision as of 16:20, 8 March 2020

This module is for producing wikitext. See also Module:UtilsLayout.

Lua error in package.lua at line 80: module 'Module:UtilsMarkup/Wikitable' not found.


local p = {}
local h = {}

p.link = require("Module:UtilsMarkup/Link").link
p.wikitable = require("Module:UtilsMarkup/Wikitable").wikitable
p.tabbedWikitable = require("Module:UtilsMarkup/Wikitable").tabbedWikitable

function p.format(text, args)
	if not args then
		return text
	end
	local frame = mw.getCurrentFrame()
	local result = text
	if args.bold then 
		result = string.format("<b>%s</b>", result)
	end
	if args.italic then
		result = string.format("<i>%s</i>", result)
	end
	if args.fontSize then
		result = string.format('<span style="font-size: %s">%s</span>', fontSize, result)
	end
	if args.pre then
		result = frame:extensionTag("pre", text)
	end
	if args.code then
		result = frame:extensionTag("code", text)
	end
	if args.nowiki then
		result = frame:extensionTag("nowiki", text)
	end
	if args.syntaxHighlight then
		result = frame:extensionTag("syntaxhighlight", text, {
			lang = args.syntaxHighlight
		})
	end
	if args.class then
		result = string.format('<span class="%s">%s</span>', args.class, result)
	end
	return result
end

return p