Skip to content

Commit

Permalink
fix(export): fix metadata values being ignored when converting to mar…
Browse files Browse the repository at this point in the history
…kdown

refactor(export): make `update_indent` also return the function needed
  • Loading branch information
ALVAROPING1 authored and vhyrro committed Dec 27, 2023
1 parent c129c7a commit 6f9b66c
Showing 1 changed file with 50 additions and 23 deletions.
73 changes: 50 additions & 23 deletions lua/neorg/modules/core/export/markdown/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"] = "___",
},

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 6f9b66c

Please sign in to comment.