Remark plugin to add title to code block
npm install remark-code-titles
Remark plugin to add code title inspired by gatsby-remark-code-titles
We have the following file, hello.md:
~~~markdown
``js:hello.js`
console.log('js')
~~~
And our script, hello.js, lokks as follows:
`js:sample.js
const vfile = require('to-vfile')
const unified = require('unified')
const parse = require('remark-parse')
const codeTitle = require('remark-code-titles')
const html = require('remark-html')
const result = unified()
.use(parse)
.use(codeTitle)
.use(html)
.process(vfile.readSync('./hello.md'), (err, file) => {
if (err) throw err
console.log(String(file))
})
`
Now, running node hello.js yields:
`html``Hello World
hello.jsconsole.log('js')