Module:String2/sandbox: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 22:
 
local prefix_patterns_t = { -- sequence of prefix patterns
'^\127[^\127]*UNIQ%-%-%a+%-%x+%-QINU[^\127]*\127', -- stripmarker
'^([%*;:#]+)', -- various list markup
'^(\'\'\'*)', -- bold / italic markup
Line 35:
local prefixes_t = {}; -- list, bold/italic, and html-like markup, & whitespace saved here
 
-- local function prefix_strip (s, prefixes_t) -- local function to strip prefixes from <s>
local function prefix_strip (s) -- local function to strip prefixes from <s>
for _, pattern in ipairs (prefix_patterns_t) do -- spin through <prefix_patterns_t>
if s:match (pattern) then -- when there is a match
Line 48 ⟶ 47:
end
 
-- local prefixes_t = {}; -- list, bold/italic, and html-like markup, & whitespace saved here
local prefix_removed; -- flag; boolean true as long as prefix_strip() finds and removes a prefix
repeat -- one by one remove list, bold/italic, html-like markup, whitespace, etc from start of <s>
-- s, prefix_removed = prefix_strip (s, prefixes_t);
s, prefix_removed = prefix_strip (s);
until (not prefix_removed); -- until <prefix_removed> is nil
 
s1 = table.concat (prefixes_t); -- recreate the prefix string for later reattachment
 
-- if it's a list chop off and (store as s1) everything up to the first <li>
-- why just list markup? Could be any sort of html markup:
-- <span title="Spanish-language text"><i lang="es">casa</i></span> (this from {{lang|es|casa}})
-- what about wikitext italic or bold markup? (''italic text'', '''bold text''') – both may be legitimate
-- local lipos = mw.ustring.find(s, "<li>" ) -- why not constrained to start of string?
-- if lipos then
-- s1 = mw.ustring.sub(s, 1, lipos + 3) -- get <li> tag (assumes that the tag is the first text in the string <s> – it may not be)
-- s = mw.ustring.sub(s, lipos + 4) -- get everything after the <li> tag
-- end
-- -- s1 is either "" or the first part of the list markup, so we can continue
-- -- and prepend s1 to the returned string
-- local letterpos
 
local first_text = mw.ustring.match (s, '^%[%[[^%]]+%]%]'); -- extract wikilink at start of string if present; TODO: this can be string.match()?
Line 100 ⟶ 84:
 
return s1 .. s; -- reattach prefix string (if present) and done
 
-- if mw.ustring.find(s, "^%[%[[^|]+|[^%]]+%]%]") then
-- -- this is a piped wikilink, so we capitalise the text, not the pipe
-- local _
-- _, letterpos = mw.ustring.find(s, "|%W*%w") -- find the first letter after the pipe
-- else
-- letterpos = mw.ustring.find(s, '%w')
-- end
-- if letterpos then
-- local first = mw.ustring.sub(s, 1, letterpos - 1)
-- local letter = mw.ustring.sub(s, letterpos, letterpos)
-- local rest = mw.ustring.sub(s, letterpos + 1)
-- return s1 .. first .. mw.ustring.upper(letter) .. rest
-- else
-- return s1 .. s
-- end
end
 
 
p.title = function (frame )