MCPcopy Create free account
hub / github.com/editablejs/editable / transform

Function transform

packages/deserializer/src/html.ts:26–54  ·  view source on GitHub ↗
(node: DOMNode, options: HTMLDeserializerOptions = {})

Source from the content-addressed store, hash-verified

24
25export const HTMLDeserializer = {
26 transform(node: DOMNode, options: HTMLDeserializerOptions = {}): Descendant[] {
27 const { element, text, matchNewline } = options
28 if (isDOMText(node)) {
29 const content = node.textContent ?? ''
30 if (
31 matchNewline &&
32 /^\s{0,}(\r\n|\n)+\s{0,}$/.test(content) &&
33 (typeof matchNewline === 'boolean' || matchNewline(content))
34 ) {
35 return []
36 }
37 const dataArray = content.split(/\r\n|\n/)
38 return dataArray.map(data => ({ ...text, text: data }))
39 }
40
41 const children = []
42 for (const child of node.childNodes) {
43 children.push(...this.transform(child, { text }))
44 }
45
46 switch (node.nodeName) {
47 case 'P':
48 case 'DIV':
49 if (children.length === 0) children.push({ text: '' })
50 return [{ ...element, type: 'paragraph', children }]
51 default:
52 return children
53 }
54 },
55
56 with<T = HTMLDeserializerOptions>(transform: HTMLDeserializerWithTransform<T>, options: T) {
57 const { transform: t } = this

Callers 1

withFunction · 0.70

Calls 1

isDOMTextFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…