#meta
util = util or {}
function printTree(tree, level)
-- recursive
local indentation = string.rep(" ", level * 2)
local response = "\n" .. indentation
local typesToSkipChildren = {
"EmphasisMark",
"CodeMark",
"LuaDirectiveMark",
"TaskMark",
"WikiLinkMark",
}
if tree.type then
response = response .. tree.type .. " (" .. tree.from .. " to " .. tree.to .. ")"
if not table.includes(typesToSkipChildren, tree.type) then
response = response .. ": "
end
else
response = response .. "Leaf: "
end
if tree.text then
local text = string.gsub(tree.text, "\n", "<newline>")
response = response .. text
end
if tree.children and not table.includes(typesToSkipChildren, tree.type) then
for child in tree.children do
response = response .. printTree(child, level + 1)
end
end
return response
end
util.prettyPrintMarkdown = function(page)
parsedPage = markdown.parseMarkdown(space.readPage(page))
return printTree(parsedPage)
end