Last active
July 23, 2020 15:18
-
-
Save onhate/39f55673603ab7563d0a3a50bc5dbd75 to your computer and use it in GitHub Desktop.
remark auto link workaround to generate correct link output format
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 remark from 'remark'; | |
import parse from 'remark-parse'; | |
import { Node } from 'unist'; | |
import visit from 'unist-util-visit'; | |
// simple trick to parse links with []() instead of <> | |
const linker = () => (tree: Node) => visit(tree, 'link', node => { | |
node.title = node.title || ''; | |
}); | |
const remarked = await remark() | |
.use(parse, { gfm: true }) | |
.use(linker) | |
.process('https://gist.github.com'); | |
// will output [https://gist.github.com](https://gist.github.com) instead of <https://gist.github.com> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment