From 6f9b66cfa75241d4b8c0890a312872104a2d96a1 Mon Sep 17 00:00:00 2001 From: ALVAROPING1 Date: Tue, 26 Dec 2023 14:35:48 +0100 Subject: [PATCH] fix(export): fix metadata values being ignored when converting to markdown refactor(export): make `update_indent` also return the function needed --- .../modules/core/export/markdown/module.lua | 73 +++++++++++++------ 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/lua/neorg/modules/core/export/markdown/module.lua b/lua/neorg/modules/core/export/markdown/module.lua index ecfdf528e..e7003063b 100644 --- a/lua/neorg/modules/core/export/markdown/module.lua +++ b/lua/neorg/modules/core/export/markdown/module.lua @@ -76,6 +76,24 @@ local function todo_item_extended(replace_text) end end +local function handle_metadata_literal(text, node, state) + if node:parent():type() == "array" then + return "\n" .. string.rep(" ", state.indent) .. "- " .. text + end + + return text +end + +local function update_indent(value) + return function(_, _, state) + return { + state = { + indent = state.indent + value, + }, + } + end +end + --> Recollector Utility Functions local function todo_item_recollector() @@ -534,33 +552,19 @@ module.public = { ["strong_carryover"] = "", ["weak_carryover"] = "", - ["key"] = true, - - [":"] = ": ", - - ["["] = function(_, _, state) - return { - state = { - indent = state.indent + 2, - }, - } - end, - ["]"] = function(_, _, state) - return { - state = { - indent = state.indent - 2, - }, - } + ["key"] = function(text, _, state) + return string.rep(" ", state.indent) .. text end, - ["value"] = function(text, node, state) - if node:parent():type() == "array" then - return "\n" .. string.rep(" ", state.indent) .. "- " .. text - end + [":"] = ": ", - return text - end, + ["["] = update_indent(2), + ["]"] = update_indent(-2), + ["{"] = update_indent(2), + ["}"] = update_indent(-2), + ["string"] = handle_metadata_literal, + ["number"] = handle_metadata_literal, ["horizontal_line"] = "___", }, @@ -641,6 +645,29 @@ module.public = { table.insert(output, "\n") return output end, + + ["object"] = function(output, state, node) + if vim.tbl_isempty(output) then + -- TODO: Handle empty value + return + end + if node:parent():type() == "array" then + output[1] = output[1]:sub(1, state.indent) .. "-" .. output[1]:sub(state.indent + 2) + end + output[1] = "\n" .. output[1] + return output + end, + ["array"] = function(output, state, node) + if vim.tbl_isempty(output) then + -- TODO: Handle empty value + return + end + if node:parent():type() == "array" then + local indent = state.indent + 1 + output[1] = output[1]:sub(1, indent) .. "-" .. output[1]:sub(indent + 2) + end + return output + end, }, cleanup = function()