remark plugin to add titles to code blocks
npm install remark-code-titleRemark plugin to add a title to code blocks.
Inspired by:
- gatsby-remark-code-titles
- remark-code-titles [currently not maintained]
| Astro | Next.js |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
|  |  |
``bash`
npm install remark-code-title
Given this markdown file example.md:
``markdownExample
`js title="example.js"`
console.log("Hello World");``
And this script, example.js, using remark-code-title:
`js
import codeTitle from "remark-code-title";
import html from "remark-html";
import { read } from "to-vfile";
import { remark } from "remark";
const processor = remark().use(codeTitle).use(html, { sanitize: false });
const markdown = await read("example.md");
const result = await processor.process(markdown);
`
Running node example.js yields:
`html``Example
example.js
console.log("Hello World");