Created
September 26, 2022 13:37
-
-
Save filiptronicek/f1f2233e484820aa59bea1250ea9842f to your computer and use it in GitHub Desktop.
Release notes parser - tailored to the new proposed Gitpod Changelog process
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
import { readFile } from "fs/promises"; | |
import { unified } from "unified/lib/index.js"; | |
import remarkParse from "remark-parse"; | |
const file = await readFile("files/file.md", "utf8"); | |
const data = unified().use(remarkParse).parse(file); | |
const releaseNotesStart = data.children.find( | |
(node) => | |
node.type === "heading" && | |
node.depth === 2 && | |
node.children[0].value === "Release Notes" | |
).position.end.offset; | |
const releaseNotesEnd = | |
data.children.find( | |
(node) => | |
node.type === "heading" && | |
node.depth === 2 && | |
node.position.start.offset > releaseNotesStart | |
).position.start.offset - 1; | |
const releaseNotes = file.slice(releaseNotesStart, releaseNotesEnd); | |
const withRemovedComments = releaseNotes.replace(/<!--([\s\S]*?)-->/g, "").trim(); // https://github.com/stevemao/html-comment-regex/blob/master/index.js | |
console.log(withRemovedComments); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment