UNPKG

gatsby-remark-dictionary

Version:

Create a dictionary of word and phrases to be converted to highlighted values and links. define once and all phrases will be converted during build time.

25 lines (18 loc) 644 B
const visit = require("unist-util-visit") const toString = require("mdast-util-to-string") module.exports = ({ markdownAST }, pluginOptions) => { visit(markdownAST, "heading", node => { let { depth } = node; // Skip if not an h1 if (depth !== 1) return; // Grab the innerText of the heading node let text = toString(node); const html = `<h1 style="color: rebeccapurple"><abbr title="text">${text}</abbr></h1>`; node.type = "html"; node.children = undefined; node.value = html; // console.log('node', node); }) // console.log(pluginOptions); return markdownAST }