datocms-html-to-structured-text
Advanced tools
Comparing version 0.1.0-alpha.23 to 0.1.0-alpha.26
@@ -89,2 +89,5 @@ "use strict"; | ||
}; | ||
if (typeof settings.preprocess === 'function') { | ||
settings.preprocess(tree); | ||
} | ||
return [4 /*yield*/, visit_node_1.default(createNode, tree, { | ||
@@ -95,2 +98,3 @@ parentNode: null, | ||
wrapText: true, | ||
defaultHandlers: handlers_1.handlers, | ||
handlers: Object.assign({}, handlers_1.handlers, settings.handlers || {}), | ||
@@ -97,0 +101,0 @@ })]; |
@@ -68,11 +68,22 @@ "use strict"; | ||
case 1: | ||
if (!(++index < nodes.length)) return [3 /*break*/, 3]; | ||
if (!(++index < nodes.length)) return [3 /*break*/, 6]; | ||
return [4 /*yield*/, visit_node_1.default(createNode, nodes[index], __assign(__assign({}, context), { parentNode: parentNode }))]; | ||
case 2: | ||
result = _a.sent(); | ||
if (result) { | ||
values = values.concat(result); | ||
} | ||
return [3 /*break*/, 1]; | ||
case 3: return [2 /*return*/, values]; | ||
result = (_a.sent()); | ||
if (!result) return [3 /*break*/, 5]; | ||
if (!Array.isArray(result)) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, Promise.all(result.map(function (nodeOrPromise) { | ||
if (nodeOrPromise instanceof Promise) { | ||
return nodeOrPromise; | ||
} | ||
return Promise.resolve(nodeOrPromise); | ||
}))]; | ||
case 3: | ||
result = (_a.sent()); | ||
_a.label = 4; | ||
case 4: | ||
values = values.concat(result); | ||
_a.label = 5; | ||
case 5: return [3 /*break*/, 1]; | ||
case 6: return [2 /*return*/, values]; | ||
} | ||
@@ -79,0 +90,0 @@ }); |
import { Root, CreateNodeFunction, HastRootNode } from './lib/types'; | ||
import parse5 from '@types/parse5'; | ||
import parse5 from 'parse5'; | ||
export declare type Settings = Partial<{ | ||
newlines: boolean; | ||
handlers: Record<string, CreateNodeFunction>; | ||
preprocess: (hast: HastRootNode) => HastRootNode; | ||
}>; | ||
@@ -7,0 +8,0 @@ export declare function htmlToDast(html: string, settings?: Settings): Promise<Root>; |
@@ -14,3 +14,3 @@ import { Node, Root, NodeType, Mark } from 'datocms-structured-text-utils'; | ||
} | ||
export declare type Handler<HastNodeType> = (createNodeFunction: CreateNodeFunction, node: HastNodeType, context: Context) => Promise<Node | Array<Node> | void>; | ||
export declare type Handler<HastNodeType> = (createNodeFunction: CreateNodeFunction, node: HastNodeType, context: Context) => Promise<Node | Array<Node> | void> | Array<Promise<Node | Array<Node> | void>>; | ||
export interface HastProperties { | ||
@@ -17,0 +17,0 @@ className?: string[]; |
{ | ||
"name": "datocms-html-to-structured-text", | ||
"version": "0.1.0-alpha.23", | ||
"version": "0.1.0-alpha.26", | ||
"description": "Convert HTML (or Hast syntax tree) to a valid DatoCMS Structured Text Dast document", | ||
@@ -34,3 +34,3 @@ "keywords": [ | ||
"dependencies": { | ||
"datocms-structured-text-utils": "^0.1.0-alpha.23", | ||
"datocms-structured-text-utils": "^0.1.0-alpha.26", | ||
"extend": "^3.0.2", | ||
@@ -49,3 +49,3 @@ "hast-util-from-dom": "^3.0.0", | ||
}, | ||
"gitHead": "19b07545c4215e706745ff4a861289097c2c7d9c" | ||
"gitHead": "c2e311dcb0ec61dcccca96cccd881760b379209b" | ||
} |
@@ -1,2 +0,2 @@ | ||
# `to-dast` | ||
# `html-to-structured-text` | ||
@@ -8,5 +8,5 @@ > TODO: description | ||
``` | ||
const toDast = require('to-dast'); | ||
const { toDast } = require('html-to-structured-text'); | ||
// TODO: DEMONSTRATE API | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
64076
967