Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/josestg/rehype-code-title

Rehype plugin to add code title.
https://github.com/josestg/rehype-code-title

mdx-prism prism rehype rehype-plugin remark remark-plugin unifiedjs

Last synced: about 1 month ago
JSON representation

Rehype plugin to add code title.

Awesome Lists containing this project

README

        

# Rehype Code Title

[![Build Status](https://travis-ci.com/josestg/rehype-code-title.svg?token=1ZtvVXXQrZXVL8domfez&branch=master)](https://travis-ci.com/josestg/rehype-code-title)
![release](https://badgen.net/github/release/josestg/rehype-code-title)
![npm](https://badgen.net/npm/v/rehype-code-title)

[Rehype](https://github.com/rehypejs/rehype) plugin to add code title.

## Install

```shell
npm i rehype-code-title

or

yarn add rehype-code-title
```

## Use

**markdown:**

````md
```tsx:pages/_app.tsx
export default class App extends NextApp {
render() {
const { Component, pageProps } = this.props
return (






)
}
}
```
````

**rehype-code-title:**

```js
import { unified } from "unified"
import remark from "remark-parse"
import remark2rehype from "remark-rehype"
import stringify from "rehype-stringify"
import codeTitle from "./index.js"
import * as vfile from "to-vfile"

function compile(file, opt) {
return unified()
.use(remark)
.use(remark2rehype)
.use(codeTitle, opt)
.use(stringify)
.processSync(vfile.readSync("./__example__/" + file))
.toString()
}

const got = compile("1.md")
console.log(got)
```

**Yields:**

```html

export default class App extends NextApp {

render() {
const { Component, pageProps } = this.props
return (
<ThemeProvider theme={theme}>
<ColorModeProvider value="light">
<CSSReset />
<Component {...pageProps} />
</ColorModeProvider>
</ThemeProvider>
)
}
}

```