🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

rehype-decorate

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-decorate

Add CSS classes to Markdown using Rehype

latest
npmnpm
Version
1.0.0-rc.5
Version published
Maintainers
1
Created
Source



rehype-decorate

Add CSS classes to Markdown using Rehype


Write prettier Markdown

rehype-decorate lets you add CSS classnames to Markdown.

# This is markdown

<!-- {.large-heading} -->

The `h1` above will have a CSS class name `large-heading` applied to it. We do
this without extending Markdown syntax. The HTML comment will be invisible
where regular Markdown parsers can't see it, making your Markdown render just
as normal Markdown.

Cool, isn't it?

Install

yarn add rehype-decorate@next

Usage

rehype-decorate works with Rehype syntax trees. These can be generated by many tools, including the Remark Markdown parser. It exposes a function, decorate(), which takes in a HAST tree, and exports a HAST tree as well:

import decorate from 'rehype-decorate'

htmlAst = decorate(htmlAst)

Unified example

Here's an example using unified, which parses Markdown via Remark, converts it to Rehype format via remark2rehype, uses rehype-decorate, then converts it to a string via rehype-stringify:

import decorate from 'rehype-decorate'
import unified from 'unified'
import stream from 'unified-stream'
import markdown from 'remark-parse'
import remark2rehype from 'remark-rehype'
import html from 'rehype-stringify'

processor = unified()
  .use(markdown)
  .use(remark2rehype)
  .use(decorate)
  .use(html)

const input = '# hello world\n\n<!-- {.heading} -->'

processor.process(input, (err, file) => {
  console.log(String(file))
})

Thanks

rehype-decorate © 2018+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).
Thanks to Chaparra for the icon.

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz

 

FAQs

Package last updated on 31 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts