Created
April 30, 2022 07:55
-
-
Save Josscii/0d64c96ccbc4536d680159c4d2f053e6 to your computer and use it in GitHub Desktop.
parse flomo html to md file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(" ", " "); | |
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