Skip to content

stefanprobst/unified-util-bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unified-util-bridge

unified plugin to process a tree in "bridge mode" and expose the result on a data property on the original processor's VFile.

How to install

yarn add @stefanprobst/unified-util-bridge

How to use

The plugin takes two required parameters: the name of the VFile data property, and a unified processor (compiler and transformers).

import { unified } from 'unified'
import fromMarkdown from 'remark-parse'
import toMarkdown from 'remark-stringify'
import strip from 'strip-markdown'
import bridge from '@stefanprobst/unified-util-bridge'
import toHast from 'remark-rehype'
import toHtml from 'rehype-stringify'

const content = '**This** is *some* text.'

const processor = unified()
  .use(fromMarkdown)
  .use(bridge, 'plaintext', unified().use(strip).use(toMarkdown))
  .use(toHast)
  .use(toHtml)
const file = processor.processSync(content)
console.log(String(file)) // markdown transformed to html
console.log(file.data.plaintext) // markdown transformed to plaintext

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published