Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/pppery/list markup
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} local yesno = require("Module:Yesno") function p.main(frame) if frame.args.text == nil then if frame.args.page == nil then frame.args.text = mw.title.getCurrentTitle():getContent() else frame.args.text = mw.title.new(frame.args.page):getContent() end end return p._main(frame.args.text,yesno(frame.args.strict)) end function p._main(text, strict) local out = "" local lastindent = "" local blanklines = "" for line in mw.text.gsplit(text, "\n") do local _, endindent = line:find("^[:*#]+") if endindent == nil then -- not an indented comment if #lastindent ~= 0 and #mw.text.trim(line) == 0 then -- buffer blank lines or lines containing whitespace until we see the next non-blank line blanklines = blanklines .. line .. "\n" else -- reset state, emitting any blank lines out = out .. blanklines .. line .. "\n" blanklines = "" lastindent = "" end else local thisindent = line:sub(1, endindent) if endindent > #lastindent then thisindent = lastindent .. line:sub(#lastindent + 1, endindent) elseif endindent == #lastindent then if strict then thisindent = lastindent else -- err on the side of keeping markup that causes visual changes, despite being incorrect if #thisindent == 1 and #lastindent == 1 and thisindent ~= lastindent then -- add back blank lines if there is going to be a breakpoint anyway out = out .. blanklines end thisindent = lastindent:sub(1, -2) .. thisindent:sub(-1) end elseif strict then thisindent = lastindent:sub(1, endindent - #lastindent - 1) else -- as before, erring on the side of keeping markup that causes a visual change if #thisindent == 1 and #lastindent == 1 and thisindent ~= lastindent then -- add back blank lines if there is going to be a breakpoint anyway out = out .. blanklines end thisindent = lastindent:sub(1, endindent - #lastindent - 2) .. thisindent:sub(-1) end blanklines = "" lastindent = thisindent out = out .. (thisindent .. line:sub(endindent + 1)) .. "\n" end end return out end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/pppery/list markup/doc
(
edit
)