Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thien-do/rehype-source-map
Attach source line number as "data-line"
https://github.com/thien-do/rehype-source-map
Last synced: 2 months ago
JSON representation
Attach source line number as "data-line"
- Host: GitHub
- URL: https://github.com/thien-do/rehype-source-map
- Owner: thien-do
- Created: 2021-09-03T03:21:10.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-09-03T04:40:31.000Z (over 3 years ago)
- Last Synced: 2024-10-09T17:55:37.325Z (3 months ago)
- Language: JavaScript
- Size: 20.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rehype-source-map
[**rehype**][rehype] plugin to attach positional info (e.g. "start-line") to elements (e.g. via the `data-line` attribute).
Input:
```md
First lineSecond line
```Output:
```html
First line
Second line
```## Install
This package is [ESM only][esm]:
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.[yarn][]:
```sh
yarn add rehype-source-map
```## Use
The plugin should be used for rehype-ed content (i.e. after `remark-rehype` or
`retext-rehype`). There is no options at the moment.```js
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
import { rehypeSourceMap } from "rehype-source-map";unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypeStringify)
.use(rehypeSourceMap)
.process(/* you know the drill */);
```[yarn]: https://yarnpkg.com/cli/add
[rehype]: https://github.com/rehypejs/rehype
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c