Module:Nowiki parameter

From Final Fantasy XIV Online Wiki
Jump to navigation Jump to search
Documentation for Module:Nowiki parameter [view] [edit] [history] [purge] (How does this work?)

This module is a single function which is used to unwrap parameters a template expects to be wrapped in a <nowiki> tag. For use in the implementation of other modules.

local nowikiParameter = require("Module:Nowiki parameter")

Used as:

function p.main(frame)
    local value, usedNowiki = nowikiParameter(frame.args[1])
    -- do stuff with value
end

Parameters

  1. A value read from frame.args. Expected to be a string or nil.

Returns

  1. The raw text wrapped by the nowiki tag. If the input
  2. A boolean that indicates whether the input was in fact wrapped in a <nowiki> tag. This can be used by templates which require input to be wrapped, to display an error to the user if unwrapped text or any other type of input was given to the parameter.
-- pattern matches a single <nowiki> strip marker with nothing else
local nowikiPattern = "^\127'\"`UNIQ%-%-nowiki%-%x+%-QINU`\"'\127$"

--- Handles a parameter value that's expected to contain text wrapped in a
--- <nowiki> tag.
--- @param value string|nil input value from `frame.args`
--- @return string|nil unstripped Unstripped contents of the nowiki tag, or nil
--- if the input was nil
--- @return boolean usedNowiki Will be true if the input did indeed contain a
--- single nowiki tag, false if the input was nil or took any other form. You
--- may want to surface an error if this is false.
return function(value)
	if not value then
		return nil, false
	end

	value = mw.text.trim(tostring(value))
	return mw.text.decode(mw.text.unstripNoWiki(value)), value:match(nowikiPattern) and true or false
end