diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-08-08 13:08:44 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-08-08 13:08:44 +0530 |
| commit | 8ec50e55a45af1706d40eff292db4541b6fcc261 (patch) | |
| tree | 6b4cb54d638765cc0c3178984a6ec18af4a3a7e4 /ldoc_json_filter.lua | |
| parent | b955a603c27ffb3869901b1899303b936816afcf (diff) | |
| download | null-browser-8ec50e55a45af1706d40eff292db4541b6fcc261.tar.gz null-browser-8ec50e55a45af1706d40eff292db4541b6fcc261.zip | |
Embed docs as null://docs + web.help api
Diffstat (limited to 'ldoc_json_filter.lua')
| -rw-r--r-- | ldoc_json_filter.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/ldoc_json_filter.lua b/ldoc_json_filter.lua new file mode 100644 index 0000000..33141cb --- /dev/null +++ b/ldoc_json_filter.lua @@ -0,0 +1,37 @@ +local function get_labels(items) + local labels = {} + for _, item in ipairs(items) do + if item.items then + for _, label in ipairs(get_labels(item.items)) do + table.insert(labels, label) + end + else + local label = table.concat(item.names_hierarchy, '.') + table.insert(labels, label) + end + end + return labels +end + +local function get_dir() + local dir = './doc' + for index, a in ipairs(arg) do + if a == '--dir' or a == '-d' then + dir = arg[index + 1] + end + end + return dir +end + +return { + lua = function(doc) + local labels = get_labels(doc) + local file_path = get_dir() .. '/symbols.json' + local file, _ = io.open(file_path, 'w+') + if file then + local symbols = require 'dkjson'.encode(labels, { indent = true }) + assert(file:write(symbols)) + end + return false + end, +} |
