Skip to content

Commit

Permalink
add 'convert lists' feature
Browse files Browse the repository at this point in the history
  • Loading branch information
lugenx committed May 9, 2023
1 parent 0197eef commit 61c83e2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion convertFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ const convertFile = (file) => {
return text?.replaceAll(/\n(.+)/g, "\n\t- $1");
};

const formatList = (list) => {
const mappedList = list?.map((item) =>
item.isChecked ? `DONE ${item.text}` : `TODO ${item.text}`
);
return mappedList?.join("\n\t- ");
};

const formatAttachments = (attachments) => {
if (!attachments) return "";
let formatted = "";
Expand All @@ -35,10 +42,13 @@ const convertFile = (file) => {

const formattedTitle = formatTitle(file.title);
const formattedText = formatText(file.textContent);
const formattedList = formatList(file.listContent);
const formattedAttachments = formatAttachments(file.attachments);
const timestamp = `${hours}:${minutes}`;

const content = `\n- ${formattedTitle} (${timestamp}) \n\t- ${formattedText} \n\t- ${formattedAttachments}`;
const content = `\n- ${formattedTitle} (${timestamp}) \n\t- ${
formattedText || formattedList || ""
} \n\t- ${formattedAttachments}`;

return { mdFileName, content };
};
Expand Down

0 comments on commit 61c83e2

Please sign in to comment.