|
|
Line 26: |
Line 26: |
| -- this is a piped wikilink, so we capitalise the text, not the pipe | | -- this is a piped wikilink, so we capitalise the text, not the pipe |
| local _ | | local _ |
| _, letterpos = mw.ustring.find(s, "|%A*%a") -- find the first letter after the pipe | | _, letterpos = mw.ustring.find(s, "|%W*%w") -- find the first letter after the pipe |
| else | | else |
| letterpos = mw.ustring.find(s, '%a') | | letterpos = mw.ustring.find(s, '%w') |
| end | | end |
| if letterpos then | | if letterpos then |
Line 94: |
Line 94: |
| local str = mw.text.trim(frame.args[1] or "") | | local str = mw.text.trim(frame.args[1] or "") |
| return mw.text.nowiki(str) | | return mw.text.nowiki(str) |
| end
| |
|
| |
| -- posnq (position, no quotes) returns the numerical start position of the first occurrence
| |
| -- of one piece of text ("match") inside another ("str").
| |
| -- It returns nil if no match is found, or if either parameter is blank.
| |
| -- It takes the text to be searched in as the first unnamed parameter, which is trimmed.
| |
| -- It takes the text to match as the second unnamed parameter, which is trimmed and
| |
| -- any double quotes " are stripped out.
| |
| p.posnq = function(frame)
| |
| local args = frame.args
| |
| local pargs = frame:getParent().args
| |
| for k, v in pairs(pargs) do
| |
| args[k] = v
| |
| end
| |
| local str = mw.text.trim(args[1] or args.source or "")
| |
| local match = mw.text.trim(args[2] or args.target or ""):gsub('"', '')
| |
| if str == "" or match == "" then return nil end
| |
| local plain = mw.text.trim(args[3] or args.plain or "")
| |
| if plain == "false" then plain = false else plain = true end
| |
| local nomatch = mw.text.trim(args[4] or args.nomatch or "")
| |
| -- just take the start position
| |
| local pos = mw.ustring.find(str, match, 1, plain) or nomatch
| |
| return pos
| |
| end | | end |
|
| |
|