Skip to content

Instantly share code, notes, and snippets.

@filiptronicek
Created September 26, 2022 13:37
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 filiptronicek/f1f2233e484820aa59bea1250ea9842f to your computer and use it in GitHub Desktop.
Save filiptronicek/f1f2233e484820aa59bea1250ea9842f to your computer and use it in GitHub Desktop.
Release notes parser - tailored to the new proposed Gitpod Changelog process
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