Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
PanEcoDevWiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:Taxonomy
Module
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
Purge cache
General
What links here
Related changes
Page information
Cargo data
Appearance
move to sidebar
hide
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 = {} -- Internal: colon-style render (for backward compatibility) local function renderNodeColon(node, indent) indent = indent or 0 local out = string.rep(":", indent) .. node.label .. "\n" for _, child in ipairs(node.children) do out = out .. renderNodeColon(child, indent + 1) end return out end -- Internal: nested <ul> render local function renderNodeUL(node) local out = "<li>" .. mw.text.nowiki(node.label) if #node.children > 0 then out = out .. "<ul>" for _, child in ipairs(node.children) do out = out .. renderNodeUL(child) end out = out .. "</ul>" end return out .. "</li>" end -- Parse a "*"-style hierarchy string into a Lua table tree function p.parse(frame) local input = frame.args[1] or "" local nodes = {} local stack = {} -- Match: one or more * followed by non-* characters for stars, label in input:gmatch("(%*+)([^%*]+)") do local level = #stars label = mw.text.trim(label) local node = { level = level, label = label, children = {} } -- Update stack stack[level] = node for i = level + 1, #stack do stack[i] = nil end -- Attach node to parent or root if level == 1 then table.insert(nodes, node) else local parent = stack[level - 1] if parent then table.insert(parent.children, node) end end end return nodes end -- Render as colon-style indented text function p.renderTree(frame) local tree = p.parse(frame) local out = "" for _, node in ipairs(tree) do out = out .. renderNodeColon(node) end return "<pre>" .. mw.text.nowiki(out) .. "</pre>" end -- Render as nested <ul> HTML list (vertical hierarchy) function p.renderTreeUL(frame) local tree = p.parse(frame) local out = "<ul>" for _, node in ipairs(tree) do out = out .. renderNodeUL(node) end out = out .. "</ul>" return out end return p
Summary:
Please note that all contributions to PanEcoDevWiki 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
PanEcoDevWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Taxonomy/doc
(
edit
)
Search
Search
Editing
Module:Taxonomy
Add topic