Regel 25: | Regel 25: | ||
local varstr = frame.args.varstr or mw.text.trim(frame.args[3]) or "@@@" | local varstr = frame.args.varstr or mw.text.trim(frame.args[3]) or "@@@" | ||
local map = frame.args.map or mw.text.trim(frame.args[4]) or "" | local map = frame.args.map or mw.text.trim(frame.args[4]) or "" | ||
− | + | local map = mw.text.nowiki( map ) | |
--optional | --optional | ||
local outputsep = frame.args.outputsep or frame.args[5] or "" | local outputsep = frame.args.outputsep or frame.args[5] or "" |
Versie van 22 sep 2023 19:12
Wiki links
[[apples]], [[pears]], [[peaches]]
- Re-expanding wiki links after mw.text.nowiki?
Templates
<i class="fa fa-file " ></i>, <i class="fa fa-map-marker " ></i>, <i class="fa fa-circle " ></i>
SMW
, ,
--[[ Module:Arraymap was created with the assumption that some syntax should be masked to avoid parsing But that may not be necessary {{#invoke:Arraymap2 |vals= |sep= |varstr= |map= |outputsep= }} ]]-- local p = {} p.map = function(frame) --mandatory local vals = frame.args.vals or mw.text.trim(frame.args[1]) or "" --local vals = mw.text.nowiki( vals ) local sep = frame.args.sep or mw.text.trim(frame.args[2]) or "," local varstr = frame.args.varstr or mw.text.trim(frame.args[3]) or "@@@" local map = frame.args.map or mw.text.trim(frame.args[4]) or "" local map = mw.text.nowiki( map ) --optional local outputsep = frame.args.outputsep or frame.args[5] or "" local outputsep = string.gsub( mw.text.trim(outputsep), [[\s]], " " ) --allow for spaces with \s local escaped = frame.args.escaped or frame.args[6] or "false" local fuzzy = frame.args.fuzzysep or frame.args[7] or "false" -- fuzzysep (need a better name) lets you use a series of single characters (OR not AND) --[[ if mw.text.trim(fuzzy) == "true" then local sepPattern = '[^' .. sep .. ')+' local valTable = {} for val in string.gmatch( vals, sepPattern ) do -- replace varstr in map with val local val = mw.text.trim( val ) local newVal = string.gsub( map, varstr, val ) table.insert( valTable, newVal ) end local newVals = table.concat( valTable, outputsep ) return newVals end --]] --Standard approach local valTable = {} local valTable = mw.text.split( vals, sep ) local mappedTable = {} for k,v in ipairs(valTable) do local v = mw.text.trim( v ) if v == "" or v == nil then --nothing else --local mapUnstripped = mw.text.unstripNoWiki( map ) local newVal = string.gsub( map, varstr, v ) --local newVal = mw.text.killMarkers( newVal ) --local newVal = frame:preprocess( newVal ) --local newVal = html:wikitext( newVal ) --local newVal = newVal .. "[" .. smwescaped .. "]" table.insert( mappedTable, newVal ) end end local res = table.concat( mappedTable, outputsep ) --local res = mw.text.unstrip( res ) --local res = mw.text.killMarkers( res ) --local res = frame:preprocess( res ) -- local res = frame:preprocess( mw.text.unstrip( newVals ) ) return res end return p