From fd95dfe2696f5f93f91bda594ae3c4fc366b8bcf Mon Sep 17 00:00:00 2001 From: Alain Date: Tue, 28 May 2024 06:37:28 -0500 Subject: [PATCH] fix #941 --- core/Objects/Item.vala | 10 ++++++++++ core/Objects/Project.vala | 20 ++++---------------- core/Util/Datetime.vala | 8 ++++++++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/core/Objects/Item.vala b/core/Objects/Item.vala index 777a7a3b1..fac1d45ae 100644 --- a/core/Objects/Item.vala +++ b/core/Objects/Item.vala @@ -1535,4 +1535,14 @@ public class Objects.Item : Objects.BaseObject { return project_id == project.id; } + + public string to_markdown (int level = 0) { + string text = "%*s- %s%s%s\n".printf (level * 2, "", checked ? "[x]" : "[ ]", Utils.Datetime.get_markdown_format_date(this), content); + + foreach (Objects.Item item in items) { + text += item.to_markdown (level + 1); + } + + return text; + } } diff --git a/core/Objects/Project.vala b/core/Objects/Project.vala index c610c1f9a..7e4f73d38 100644 --- a/core/Objects/Project.vala +++ b/core/Objects/Project.vala @@ -768,36 +768,24 @@ public class Objects.Project : Objects.BaseObject { private string to_markdown () { string text = ""; - text += "# %s\n".printf (name); - + text += "## %s\n".printf (name); foreach (Objects.Item item in items) { - text += "- [%s] %s\n".printf (item.checked ? "x" : " ", item.content); + text += item.to_markdown (); } foreach (Objects.Section section in sections) { text += "\n"; - text += "## %s\n".printf (section.name); + text += "### %s\n".printf (section.name); foreach (Objects.Item item in section.items) { - text += "- [%s]%s%s\n".printf (item.checked ? "x" : " ", get_format_date (item), item.content); - foreach (Objects.Item check in item.items) { - text += " - [%s]%s%s\n".printf (check.checked ? "x" : " ", get_format_date (check), check.content); - } + text += item.to_markdown (); } } return text; } - private string get_format_date (Objects.Item item) { - if (!item.has_due) { - return " "; - } - - return " (" + Utils.Datetime.get_relative_date_from_date (item.due.datetime) + ") "; - } - public void delete_project (Gtk.Window window) { var dialog = new Adw.AlertDialog ( _("Delete Project %s?".printf (name)), diff --git a/core/Util/Datetime.vala b/core/Util/Datetime.vala index 0e78042bd..ac0ae14bf 100644 --- a/core/Util/Datetime.vala +++ b/core/Util/Datetime.vala @@ -568,4 +568,12 @@ public class Utils.Datetime { return result; } + + public static string get_markdown_format_date (Objects.Item item) { + if (!item.has_due) { + return " "; + } + + return " (" + get_relative_date_from_date (item.due.datetime) + ") "; + } }