- Notifications
You must be signed in to change notification settings - Fork6
HTML processor to parse and compile with browser APIs, powered by plugins
License
rehypejs/rehype-dom
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This project is a monorepo that contains alternatives torehype for use inbrowsers.
This monorepo contains the following packages:
rehype-dom-parse
— plugin to take HTML as input and turn it into a syntax tree (hast) inbrowsersrehype-dom-stringify
— plugin to take a syntax tree (hast) and turn it into HTML as output inbrowsersrehype-dom
—unified
,rehype-dom-parse
, andrehype-dom-stringify
, useful wheninput and output are HTML
You can use this project when you want to use rehype in browsers.It has a smaller footprint in browsers compared torehype
itself as it usesDOM APIs to do its work.However, DOM APIs:
- …cannot provide positional information (each node knowing where itoriginated), which is frequently needed when working with rehype
- …do not have formatting options that
rehype-stringify
exposes - …can provide varying results in different (especially older) browsers
- …are safe, but untrusted HTML in browsers is always unsafe
Say our pageexample.html
looks as follows:
<!doctype html><title>Example</title><body><scripttype="module">import{rehypeDom}from'https://esm.sh/rehype-dom@7?bundle'constfile=awaitrehypeDom().process('<h1>Hi <del>Mars</del>Venus!</h1>')document.body.innerHTML=String(file)</script>
Now runningopen example.html
renders the following in<body>
:
<h1>Hi<del>Mars</del>Venus!</h1>
Use ofrehype-dom
can open you up to across-site scripting (XSS)attack if dangerous content is used and the result is used with the actual DOM.Userehype-sanitize
to solve that.
Seecontributing.md
inrehypejs/.github
for waysto get started.Seesupport.md
for ways to get help.
This project has acode of conduct.By interacting with this repository, organisation, or community you agree toabide by its terms.
About
HTML processor to parse and compile with browser APIs, powered by plugins