@portabletext/to-html
Advanced tools
@@ -160,2 +160,6 @@ import type {ArbitraryTypedObject} from '@portabletext/types' | ||
| /** | ||
| * Used when rendering text nodes to HTML | ||
| */ | ||
| escapeHTML: (html: string) => string | ||
| /** | ||
| * Component function used when encountering a mark type there is no registered component for | ||
@@ -162,0 +166,0 @@ * in the `components.marks` prop. |
@@ -160,2 +160,6 @@ import type {ArbitraryTypedObject} from '@portabletext/types' | ||
| /** | ||
| * Used when rendering text nodes to HTML | ||
| */ | ||
| escapeHTML: (html: string) => string | ||
| /** | ||
| * Component function used when encountering a mark type there is no registered component for | ||
@@ -162,0 +166,0 @@ * in the `components.marks` prop. |
+19
-15
@@ -17,14 +17,3 @@ "use strict"; | ||
| var toolkit = require("@portabletext/toolkit"); | ||
| const defaultLists = { | ||
| number: ({ | ||
| children | ||
| }) => `<ol>${children}</ol>`, | ||
| bullet: ({ | ||
| children | ||
| }) => `<ul>${children}</ul>` | ||
| }, | ||
| DefaultListItem = ({ | ||
| children | ||
| }) => `<li>${children}</li>`, | ||
| allowedProtocols = ["http", "https", "mailto", "tel"], | ||
| const allowedProtocols = ["http", "https", "mailto", "tel"], | ||
| charMap = { | ||
@@ -38,4 +27,7 @@ "&": "amp", | ||
| function escapeHTML(str) { | ||
| return str.replace(/[&<>"']/g, s => `&${charMap[s]};`); | ||
| return replaceMultipleSpaces(str.replace(/[&<>"']/g, s => `&${charMap[s]};`)); | ||
| } | ||
| function replaceMultipleSpaces(str) { | ||
| return str.replace(/ {2,}/g, match => `${" ".repeat(match.length - 1)} `); | ||
| } | ||
| function uriLooksSafe(uri) { | ||
@@ -54,3 +46,14 @@ const url = (uri || "").trim(), | ||
| } | ||
| const link = ({ | ||
| const defaultLists = { | ||
| number: ({ | ||
| children | ||
| }) => `<ol>${children}</ol>`, | ||
| bullet: ({ | ||
| children | ||
| }) => `<ul>${children}</ul>` | ||
| }, | ||
| DefaultListItem = ({ | ||
| children | ||
| }) => `<li>${children}</li>`, | ||
| link = ({ | ||
| children, | ||
@@ -143,2 +146,3 @@ value | ||
| hardBreak: DefaultHardBreak, | ||
| escapeHTML, | ||
| unknownType: DefaultUnknownType, | ||
@@ -314,3 +318,3 @@ unknownMark: DefaultUnknownMark, | ||
| } | ||
| return escapeHTML(node.text); | ||
| return components.escapeHTML(node.text); | ||
| } | ||
@@ -317,0 +321,0 @@ function renderCustomBlock(value, index, isInline) { |
+19
-15
@@ -12,14 +12,3 @@ const _excluded = ["block", "list", "listItem", "marks", "types"], | ||
| import { nestLists, isPortableTextToolkitList, isPortableTextListItemBlock, isPortableTextToolkitSpan, isPortableTextBlock, isPortableTextToolkitTextNode, spanToPlainText, buildMarksTree } from "@portabletext/toolkit"; | ||
| const defaultLists = { | ||
| number: ({ | ||
| children | ||
| }) => `<ol>${children}</ol>`, | ||
| bullet: ({ | ||
| children | ||
| }) => `<ul>${children}</ul>` | ||
| }, | ||
| DefaultListItem = ({ | ||
| children | ||
| }) => `<li>${children}</li>`, | ||
| allowedProtocols = ["http", "https", "mailto", "tel"], | ||
| const allowedProtocols = ["http", "https", "mailto", "tel"], | ||
| charMap = { | ||
@@ -33,4 +22,7 @@ "&": "amp", | ||
| function escapeHTML(str) { | ||
| return str.replace(/[&<>"']/g, s => `&${charMap[s]};`); | ||
| return replaceMultipleSpaces(str.replace(/[&<>"']/g, s => `&${charMap[s]};`)); | ||
| } | ||
| function replaceMultipleSpaces(str) { | ||
| return str.replace(/ {2,}/g, match => `${" ".repeat(match.length - 1)} `); | ||
| } | ||
| function uriLooksSafe(uri) { | ||
@@ -49,3 +41,14 @@ const url = (uri || "").trim(), | ||
| } | ||
| const link = ({ | ||
| const defaultLists = { | ||
| number: ({ | ||
| children | ||
| }) => `<ol>${children}</ol>`, | ||
| bullet: ({ | ||
| children | ||
| }) => `<ul>${children}</ul>` | ||
| }, | ||
| DefaultListItem = ({ | ||
| children | ||
| }) => `<li>${children}</li>`, | ||
| link = ({ | ||
| children, | ||
@@ -138,2 +141,3 @@ value | ||
| hardBreak: DefaultHardBreak, | ||
| escapeHTML, | ||
| unknownType: DefaultUnknownType, | ||
@@ -309,3 +313,3 @@ unknownMark: DefaultUnknownMark, | ||
| } | ||
| return escapeHTML(node.text); | ||
| return components.escapeHTML(node.text); | ||
| } | ||
@@ -312,0 +316,0 @@ function renderCustomBlock(value, index, isInline) { |
+1
-1
| { | ||
| "name": "@portabletext/to-html", | ||
| "version": "2.0.15", | ||
| "version": "2.0.16", | ||
| "description": "Render Portable Text to HTML", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
| import type {PortableTextBlockStyle} from '@portabletext/types' | ||
| import {escapeHTML} from '../escape' | ||
| import type {PortableTextBlockComponent, PortableTextHtmlComponents} from '../types' | ||
@@ -38,2 +39,3 @@ import {DefaultListItem, defaultLists} from './list' | ||
| hardBreak: DefaultHardBreak, | ||
| escapeHTML: escapeHTML, | ||
@@ -40,0 +42,0 @@ unknownType: DefaultUnknownType, |
+5
-1
@@ -11,5 +11,9 @@ const allowedProtocols = ['http', 'https', 'mailto', 'tel'] | ||
| export function escapeHTML(str: string): string { | ||
| return str.replace(/[&<>"']/g, (s) => `&${charMap[s]};`) | ||
| return replaceMultipleSpaces(str.replace(/[&<>"']/g, (s) => `&${charMap[s]};`)) | ||
| } | ||
| export function replaceMultipleSpaces(str: string): string { | ||
| return str.replace(/ {2,}/g, (match: string) => `${' '.repeat(match.length - 1)} `) | ||
| } | ||
| export function uriLooksSafe(uri: string): boolean { | ||
@@ -16,0 +20,0 @@ const url = (uri || '').trim() |
+1
-2
@@ -24,3 +24,2 @@ import { | ||
| import {mergeComponents} from './components/merge' | ||
| import {escapeHTML} from './escape' | ||
| import type { | ||
@@ -193,3 +192,3 @@ HtmlPortableTextList, | ||
| return escapeHTML(node.text) | ||
| return components.escapeHTML(node.text) | ||
| } | ||
@@ -196,0 +195,0 @@ |
+5
-0
@@ -142,2 +142,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| /** | ||
| * Used when rendering text nodes to HTML | ||
| */ | ||
| escapeHTML: (html: string) => string | ||
| /** | ||
| * Component function used when encountering a mark type there is no registered component for | ||
@@ -144,0 +149,0 @@ * in the `components.marks` prop. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
138522
1.31%1652
1.23%