2022-09-18 16:59:57 +00:00
|
|
|
local wea_c = worldeditadditions_core
|
2021-05-30 15:18:08 +00:00
|
|
|
|
|
|
|
local function get_reference()
|
|
|
|
local lines = {}
|
2022-09-18 16:59:57 +00:00
|
|
|
for line in io.lines(wea_c.modpath.."/Chat-Command-Reference.md") do
|
2021-05-30 15:18:08 +00:00
|
|
|
table.insert(lines, line)
|
|
|
|
end
|
|
|
|
return lines
|
|
|
|
end
|
|
|
|
|
|
|
|
local function group_by_heading(lines, max_level)
|
|
|
|
local groups = {}
|
|
|
|
local acc = {}
|
|
|
|
|
|
|
|
for i,line in ipairs(lines) do
|
2022-09-18 16:59:57 +00:00
|
|
|
if wea_c.str_starts(line, "#") then
|
2021-05-30 15:18:08 +00:00
|
|
|
local _, _, heading, headingtext = line:find("(#+)%s*(.*)")
|
|
|
|
if #heading <= max_level then
|
|
|
|
table.insert(groups, {
|
|
|
|
level = #heading,
|
|
|
|
heading = headingtext,
|
|
|
|
text = table.concat(acc, "\n")
|
|
|
|
})
|
|
|
|
acc = {}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
table.insert(acc, line)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return groups
|
|
|
|
end
|
|
|
|
|
2022-09-18 16:59:57 +00:00
|
|
|
local function parse_reference()
|
2021-05-30 15:18:08 +00:00
|
|
|
local lines = get_reference()
|
2022-09-18 16:59:57 +00:00
|
|
|
local headings = wea_c.table.filter(
|
2021-05-30 15:18:08 +00:00
|
|
|
group_by_heading(lines, 2),
|
|
|
|
function(item, i) return item.level ~= 2 end
|
|
|
|
)
|
|
|
|
for i,value in ipairs(headings) do
|
2021-07-30 19:07:08 +00:00
|
|
|
print(i, "level", value.level, "heading", value.heading, "text", value.text)
|
2021-05-30 15:18:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-18 16:59:57 +00:00
|
|
|
return parse_reference
|