Skip to content

Commit

Permalink
feat: safeHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Jan 8, 2024
1 parent 4f24d0e commit ff454a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export { xml } from './xml'
export { handleHTML } from './manipulate'
export { serializeMarkdown } from './serialize-markdown'
export { serializePlaintext } from './serialize-plaintext'
export { serializeSafeHTML } from './serialize-safehtml'
export { serializeSafeHTML, safeHTML } from './serialize-safehtml'
5 changes: 5 additions & 0 deletions src/serialize-safehtml.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { escapeHTML } from './encoding'
import { VNode, isVElement } from './vdom'
import { parseHTML } from './vdomparser'

export const SELECTOR_BLOCK_ELEMENTS = 'p,h1,h2,h3,h4,h5,h6,blockquote,div,ul,ol,li,article,section,footer,nav,hr,form'

Expand Down Expand Up @@ -47,3 +48,7 @@ function serialize(node: VNode, context: SerializeContext = {
export function serializeSafeHTML(node: VNode): string {
return serialize(node).trim()
}

export function safeHTML(html: string) {
return serializeSafeHTML(parseHTML(html))
}

0 comments on commit ff454a0

Please sign in to comment.