https://github.com/mottox2/remark-code-titles
https://github.com/mottox2/remark-code-titles
remark-plugin
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/mottox2/remark-code-titles
- Owner: mottox2
- Created: 2019-01-30T13:03:35.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-01T14:56:51.000Z (about 5 years ago)
- Last Synced: 2025-03-20T05:48:51.971Z (over 1 year ago)
- Topics: remark-plugin
- Language: JavaScript
- Size: 8.79 KB
- Stars: 16
- Watchers: 1
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# remark-code-titles
[](https://badge.fury.io/js/remark-code-titles)
[Remark](https://github.com/remarkjs/remark) plugin to add code title inspired by [gatsby-remark-code-titles](https://github.com/DSchau/gatsby-remark-code-titles)
## Usage
We have the following file, `hello.md`:
~~~markdown
# Hello World
```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.js
console.log('js')
```