(
highlight: (text: string, language: string) => Delta,
forced = false,
)
| 115 | } |
| 116 | |
| 117 | highlight( |
| 118 | highlight: (text: string, language: string) => Delta, |
| 119 | forced = false, |
| 120 | ) { |
| 121 | if (this.children.head == null) return; |
| 122 | const nodes = Array.from(this.domNode.childNodes).filter( |
| 123 | (node) => node !== this.uiNode, |
| 124 | ); |
| 125 | const text = `${nodes.map((node) => node.textContent).join('\n')}\n`; |
| 126 | const language = SyntaxCodeBlock.formats(this.children.head.domNode); |
| 127 | if (forced || this.forceNext || this.cachedText !== text) { |
| 128 | if (text.trim().length > 0 || this.cachedText == null) { |
| 129 | const oldDelta = this.children.reduce((delta, child) => { |
| 130 | // @ts-expect-error |
| 131 | return delta.concat(blockDelta(child, false)); |
| 132 | }, new Delta()); |
| 133 | const delta = highlight(text, language); |
| 134 | oldDelta.diff(delta).reduce((index, { retain, attributes }) => { |
| 135 | // Should be all retains |
| 136 | if (!retain) return index; |
| 137 | if (attributes) { |
| 138 | Object.keys(attributes).forEach((format) => { |
| 139 | if ( |
| 140 | [SyntaxCodeBlock.blotName, CodeToken.blotName].includes(format) |
| 141 | ) { |
| 142 | // @ts-expect-error |
| 143 | this.formatAt(index, retain, format, attributes[format]); |
| 144 | } |
| 145 | }); |
| 146 | } |
| 147 | // @ts-expect-error |
| 148 | return index + retain; |
| 149 | }, 0); |
| 150 | } |
| 151 | this.cachedText = text; |
| 152 | this.forceNext = false; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | html(index: number, length: number) { |
| 157 | const [codeBlock] = this.children.find(index); |
nothing calls this directly
no test coverage detected