Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-remark-html

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

vite-remark-html

Process markdown with remark-html

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
decreased by-10.86%
Maintainers
1
Weekly downloads
 
Created
Source

vite-remark-html

npm Code style: Prettier Donate

Process markdown with remark-html

Basically, when you import a .md file, you'll get back a JS module with an HTML string as its default export. There are various options to customize the HTML output.

 

Usage

import remarkHtml from 'vite-remark-html'

export default {
  plugins: [remarkHtml()],
}

Remark plugins

To add Remark plugins, call the use method on the Vite plugin. It returns the Vite plugin, so you can easily chain together multiple .use calls.

import remarkHtml from 'vite-remark-html'
import remarkSlug from 'remark-slug'

export default {
  plugins: [remarkHtml().use(remarkSlug)],
}

Filter options

Markdown files can be filtered, in case you only want a subset to be processed by this plugin.

remarkHtml({
  exclude: /\/node_modules\//,
})

For more details, see here.

HTML options

All options listed here are also supported.

remarkHtml({
  allowDangerousHtml: true,
})

Using the HTML

In your client code, you can use import or dynamic import() to load the HTML string.

import html from './test.md'
// or
const htmlPromise = import('./test.md').then(module => module.default)

Then you can use that as the innerHTML of another element.

document.getElementById('markdown').innerHTML = html
// or
<div dangerouslySetInnerHtml={{ __html: html }} />

Try the demo to see it in action.

TypeScript usage

In your tsconfig.json

{
  "compilerOptions": {
    "types": ["vite-remark-html/client"]
  }
}

This lets you import .md files with type-checking support.

Keywords

FAQs

Package last updated on 28 Jul 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc