Skip to content

Instantly share code, notes, and snippets.

@Josscii
Created April 30, 2022 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Josscii/0d64c96ccbc4536d680159c4d2f053e6 to your computer and use it in GitHub Desktop.
Save Josscii/0d64c96ccbc4536d680159c4d2f053e6 to your computer and use it in GitHub Desktop.
parse flomo html to md file
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const fs = require("fs");
const files = [
"202012.html",
"202111.html",
"202112.html",
"202201.html",
"202202.html",
"202203.html",
"202204.html",
];
files.forEach((file) => {
const fileString = fs.readFileSync(file, "utf8");
const dom = new JSDOM(fileString);
const memos = dom.window.document.querySelectorAll(".memo");
memos.forEach((memo) => {
const time = memo.querySelector(".time").textContent;
let content = memo.querySelector(".content").innerHTML;
content = content.replaceAll("</p><p>", "\n");
content = content.replaceAll("<p>", "");
content = content.replaceAll("</p>", "");
content = content.replaceAll("<strong>", "**");
content = content.replaceAll("</strong>", "**");
content = content.replaceAll("<ol>", "\n");
content = content.replaceAll("<ul>", "\n");
content = content.replaceAll("<li>", "\n- ");
content = content.replaceAll("&nbsp;", " ");
content = content.replaceAll("</li>", "");
content = content.replaceAll("</ul>", "");
content = content.replaceAll("</ol>", "");
const output = `---
date: ${time}
---
${content.trim()}
`;
fs.writeFileSync(`flomo/${time}.md`, output);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment