Module:code

Hello, you have come here looking for the meaning of the word Module:code. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:code, but we will also tell you about its etymology, its characteristics and you will know how to say Module:code in singular and plural. Everything you need to know about the word Module:code you have here. The definition of the word Module:code will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:code, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module implements the template {{code}}.


local decode_entities = require("Module:string utilities").decode_entities
local gsub = string.gsub
local insert = table.insert
local match = string.match
local process_params = require("Module:parameters").process
local tonumber = tonumber
local unstripNoWiki = mw.text.unstripNoWiki
local yesno = require("Module:yesno")

local export = {}

local function get_args(frame)
	local params = {
		 = {required = true, default = "code"},
		 = {alias_of = 1},
		 = true,
		 = true,
		 = {type = "boolean"},
		 = true,
		 = true,
	}
	
	local lang = process_params(frame.args, {
		 = true
	}).lang
	local args = frame:getParent().args
	
	-- Specialised language templates (e.g. {{lua}}).
	if lang then
		args = process_params(args, params)
		return args, lang, args
	end
	
	params = {default = "text"}
	
	-- If 2= or "=..." are given, treat 1= as an alias of lang=.
	if args or args then
		insert(params, 1, {alias_of = "lang"})
		params.alias_of = 2
		args = process_params(args, params)
		return args, args.lang, args
	end
	
	-- Otherwise, 1= is just the input text.
	args = process_params(args, params)
	return args, args.lang, args
end

function export.show(frame)
	local args, lang, text = get_args(frame)
	
	lang = lang == "js" and "javascript" or lang == "py" and "python" or lang
	
	local inline, line, start, highlight = args.inline
	if not inline then
		line = args.line
		if line then
			start = match(line, "^%d+$")
			if not start then
				line = yesno(line) or nil
			end
		end
		highlight = args.highlight
		if start then
			local offset = tonumber(start) - 1
			highlight = gsub(highlight, "%d+", function(n)
				return tonumber(n) - offset
			end)
		end
		inline = inline == nil and not (line or highlight) or nil
	end
	
	-- Unstrip nowiki tags and decode any HTML entities, because
	-- syntaxhighlight won't decode them on display.
	return frame:extensionTag(
		"syntaxhighlight",
		decode_entities(unstripNoWiki(text)), {
		lang = lang,
		line = line,
		start = start,
		highlight = highlight,
		inline = inline,
		class = args.class,
		style = args.style or inline and "white-space:pre-wrap;" or nil
	})
end

return export