Conversation
|
remcohaszing
left a comment
There was a problem hiding this comment.
I added some tips, but really the tools you’re currently using are fine as-is too. :)
|
|
||
| export function getChangelogEntry(changelog: string, version: string) { | ||
| let ast = unified().use(remarkParse).parse(changelog) as Root; | ||
| let ast = unified().use(remarkParse).parse(changelog); |
There was a problem hiding this comment.
Should you support GFM and/or frontmatter here? Is so, you should use remark-gfm / remark-frontmatter.
Unless you need options passed into the function, I recommend to define the processor once outside of the function. This way plugins can cache some of the heavy lifting. This isn’t really applicable to your case, but IMO it’s a good practice. If you use GFM/frontmatter, this also allows you to keep the processor in sync with the stringify processor you use below.
const processor = unified()
.use(remarkParse)
.use(remarkFrontmatter)
.use(remarkGfm)
.use(remarkStringify)
// …
let ast = processor.parse(changelog)If you don’t want any of that, the remark abstractions don’t really offer much. You might as well use the slightly lower level mdast-util-from-markdown and mdast-util-to-markdown.
There was a problem hiding this comment.
Thanks for the review! ❤️
cc @remcohaszing, maybe you'd have a sec to double-check if I'm using the most kosher tools here? 😅