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

datocms-html-to-structured-text

Package Overview
Dependencies
Maintainers
6
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datocms-html-to-structured-text - npm Package Compare versions

Comparing version 2.1.10 to 2.1.11

8

dist/cjs/handlers.js

@@ -116,8 +116,10 @@ "use strict";

return __awaiter(this, void 0, void 0, function () {
var isAllowedChild, children;
var level, isAllowedChild, children;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
level = Number(node.tagName.charAt(1)) || 1;
isAllowedChild = datocms_structured_text_utils_1.allowedChildren[context.parentNodeType].includes('heading') &&
context.allowedBlocks.includes('heading');
context.allowedBlocks.includes('heading') &&
context.allowedHeadingLevels.includes(level);
return [4 /*yield*/, visit_children_1.default(createNode, node, __assign(__assign({}, context), { parentNodeType: isAllowedChild ? 'heading' : context.parentNodeType, wrapText: isAllowedChild ? false : context.wrapText }))];

@@ -129,3 +131,3 @@ case 1:

? createNode('heading', {
level: Number(node.tagName.charAt(1)) || 1,
level: level,
children: children,

@@ -132,0 +134,0 @@ })

@@ -129,2 +129,5 @@ "use strict";

: datocms_structured_text_utils_1.defaultMarks,
allowedHeadingLevels: Array.isArray(options.allowedHeadingLevels)
? options.allowedHeadingLevels
: [1, 2, 3, 4, 5, 6],
global: __assign({ baseUrl: null, baseUrlFound: false }, (options.shared || {})),

@@ -131,0 +134,0 @@ })];

@@ -107,8 +107,10 @@ var __assign = (this && this.__assign) || function () {

return __awaiter(this, void 0, void 0, function () {
var isAllowedChild, children;
var level, isAllowedChild, children;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
level = Number(node.tagName.charAt(1)) || 1;
isAllowedChild = allowedChildren[context.parentNodeType].includes('heading') &&
context.allowedBlocks.includes('heading');
context.allowedBlocks.includes('heading') &&
context.allowedHeadingLevels.includes(level);
return [4 /*yield*/, visitChildren(createNode, node, __assign(__assign({}, context), { parentNodeType: isAllowedChild ? 'heading' : context.parentNodeType, wrapText: isAllowedChild ? false : context.wrapText }))];

@@ -120,3 +122,3 @@ case 1:

? createNode('heading', {
level: Number(node.tagName.charAt(1)) || 1,
level: level,
children: children,

@@ -123,0 +125,0 @@ })

@@ -5,3 +5,3 @@ import { Handler, HastRootNode } from './types';

import parse5 from 'parse5';
import { Document, Mark, BlockquoteType, CodeType, HeadingType, LinkType, ListType } from 'datocms-structured-text-utils';
import { Document, Mark, BlockquoteType, CodeType, HeadingType, LinkType, ListType, Heading } from 'datocms-structured-text-utils';
export declare type Options = Partial<{

@@ -12,2 +12,3 @@ newlines: boolean;

allowedBlocks: Array<BlockquoteType | CodeType | HeadingType | LinkType | ListType>;
allowedHeadingLevels: Heading['level'][];
allowedMarks: Mark[];

@@ -14,0 +15,0 @@ }>;

@@ -109,2 +109,5 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */

: defaultMarks,
allowedHeadingLevels: Array.isArray(options.allowedHeadingLevels)
? options.allowedHeadingLevels
: [1, 2, 3, 4, 5, 6],
global: __assign({ baseUrl: null, baseUrlFound: false }, (options.shared || {})),

@@ -111,0 +114,0 @@ })];

@@ -5,3 +5,3 @@ import { Handler, HastRootNode } from './types';

import parse5 from 'parse5';
import { Document, Mark, BlockquoteType, CodeType, HeadingType, LinkType, ListType } from 'datocms-structured-text-utils';
import { Document, Mark, BlockquoteType, CodeType, HeadingType, LinkType, ListType, Heading } from 'datocms-structured-text-utils';
export declare type Options = Partial<{

@@ -12,2 +12,3 @@ newlines: boolean;

allowedBlocks: Array<BlockquoteType | CodeType | HeadingType | LinkType | ListType>;
allowedHeadingLevels: Heading['level'][];
allowedMarks: Mark[];

@@ -14,0 +15,0 @@ }>;

{
"name": "datocms-html-to-structured-text",
"version": "2.1.10",
"version": "2.1.11",
"description": "Convert HTML (or a `hast` syntax tree) to a valid DatoCMS Structured Text `dast` document",

@@ -52,3 +52,3 @@ "keywords": [

},
"gitHead": "5f9cdbf47286da519fc0663fd74a408e188b273c"
"gitHead": "f79aa0f233ebc517038a95fda6f0bc475951e7d8"
}

@@ -80,12 +80,14 @@ # `datocms-html-to-structured-text`

newlines: boolean,
// Override existing `hast` node handlers or add new ones.
// Override existing `hast` node handlers or add new ones
handlers: Record<string, CreateNodeFunction>,
// Allows to tweak the `hast` tree before transforming it to a `dast` document.
// Allows to tweak the `hast` tree before transforming it to a `dast` document
preprocess: (hast: HastRootNode) => HastRootNode,
// Array of allowed Block nodes.
// Array of allowed block nodes
allowedBlocks: Array<
BlockquoteType | CodeType | HeadingType | LinkType | ListType,
>,
// Array of allowed marks.
// Array of allowed marks
allowedMarks: Mark[],
// Array of allowed heading levels for 'heading' nodes
allowedHeadingLevels: Array<1 | 2 | 3 | 4 | 5 | 6>,
}>;

@@ -92,0 +94,0 @@ ```

@@ -90,5 +90,8 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */

) {
const level = Number(node.tagName.charAt(1)) || 1;
const isAllowedChild =
allowedChildren[context.parentNodeType].includes('heading') &&
context.allowedBlocks.includes('heading');
context.allowedBlocks.includes('heading') &&
context.allowedHeadingLevels.includes(level);

@@ -104,3 +107,3 @@ const children = await visitChildren(createNode, node, {

? createNode('heading', {
level: Number(node.tagName.charAt(1)) || 1,
level,
children,

@@ -107,0 +110,0 @@ })

@@ -23,2 +23,3 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */

ListType,
Heading,
} from 'datocms-structured-text-utils';

@@ -33,2 +34,3 @@

>;
allowedHeadingLevels: Heading['level'][];
allowedMarks: Mark[];

@@ -86,2 +88,5 @@ }>;

: defaultMarks,
allowedHeadingLevels: Array.isArray(options.allowedHeadingLevels)
? options.allowedHeadingLevels
: [1, 2, 3, 4, 5, 6],
global: {

@@ -88,0 +93,0 @@ baseUrl: null,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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