Skip to content

Commit 9a1d8a6

Browse files
committed
Add Text.splitText() method to linkedom. (mathjax/MathJax#3134)
1 parent 8b7867e commit 9a1d8a6

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

ts/adaptors/linkedomAdaptor.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ export class LinkedomAdaptor extends NodeMixin<HTMLElement, Text, Document, HTML
6666
*/
6767
export function linkedomAdaptor(parseHTML: any, options: OptionList = null): LinkedomAdaptor {
6868
const window = parseHTML('<html></html>');
69-
window.HTMLCollection = class {}; // add fake class for missing HTMLCollecton
69+
//
70+
// Add fake class for missing HTMLCollection
71+
//
72+
window.HTMLCollection = class {};
73+
//
74+
// Add missing splitText() method
75+
//
76+
window.Text.prototype.splitText = function (offset: number) {
77+
const text = this.data;
78+
if (offset > text.length) {
79+
throw Error('Index Size Error');
80+
}
81+
const newNode = window.document.createTextNode(text.substring(offset));
82+
this.parentNode.insertBefore(newNode, this.nextSibling);
83+
this.data = text.substring(0, offset);
84+
return newNode;
85+
};
7086
return new LinkedomAdaptor(window, options);
7187
}

0 commit comments

Comments
 (0)