@codesync/kses
TypeScript icon, indicating that this package has built-in type declarations

2.1.5 • Public • Published

Equivalent of wp_kses / wp_kses_post in JavaScript/Node.js

Safely render HTML in React or any other JavaScript environment. Works in both Node.js and the browser.

Example JavaScript

import { kses } from '@codesync/kses'

const unsafeHtml = '<strong>Test parser</strong><script>alert("hello")</script>'
const safeHtml = kses(unsafeHtml)
// Output: <strong>Test parser</strong>

Example React

'use client'
import { kses } from '@codesync/kses'

export default function ClientPage() {
  const unsafeHtml =
    '<strong>Test parser</strong><script>alert("hello")</script>'
  const safeHtml = kses(unsafeHtml)

  // Output: <div><strong>Test parser</strong></div>
  return <div dangerouslySetInnerHTML={{ __html: safeHtml }} />
}

Example RSC

import { kses } from '@codesync/kses/server'

export default function ServerPage() {
  const unsafeHtml =
    '<strong>Test parser</strong><script>alert("hello")</script>'
  const safeHtml = kses(unsafeHtml)

  // Output: <div><strong>Test parser</strong></div>
  return <div dangerouslySetInnerHTML={{ __html: safeHtml }} />
}

Readme

Keywords

Package Sidebar

Install

npm i @codesync/kses

Weekly Downloads

6

Version

2.1.5

License

MIT

Unpacked Size

988 kB

Total Files

12

Last publish

Collaborators

  • codesync