; its format clashes with
- node.querySelectorAll('CODE').forEach(el => detach(el));
+ node.querySelectorAll("CODE").forEach(el => detach(el));
if (output.childNodes.length) {
- output.append(doc.createTextNode('\n'));
+ output.append(doc.createTextNode("\n"));
}
output.append(empty(node));
}
// 4. Replace nbsp with regular sp
walker = createTreeWalker(output, SHOW_TEXT);
- while ((node = walker.nextNode())) {
+ while (node = walker.nextNode()) {
node.data = node.data.replace(NBSP, ' '); // nbsp -> sp
}
output.normalize();
- return fixCursor(createElement('PRE',
- null, [
+ return fixCursor(
+ createElement("PRE", null, [
output
- ]));
+ ])
+ );
}, range).focus();
}
- return this.changeFormat({ tag: 'CODE' }, null, range);
+ return this.changeFormat({ tag: "CODE" }, null, range);
}
removeCode() {
let range = this.getSelection();
let ancestor = range.commonAncestorContainer;
- let inPre = getClosest(ancestor, this._root, 'PRE');
+ let inPre = getClosest(ancestor, this._root, "PRE");
if (inPre) {
return this.modifyBlocks(frag => {
let root = this._root;
- let pres = frag.querySelectorAll('PRE');
+ let pres = frag.querySelectorAll("PRE");
let l = pres.length;
let pre, walker, node, value, contents, index;
while (l--) {
pre = pres[l];
walker = createTreeWalker(pre, SHOW_TEXT);
- while ((node = walker.nextNode())) {
+ while (node = walker.nextNode()) {
value = node.data;
value = value.replace(/ (?=)/g, NBSP); // sp -> nbsp
contents = doc.createDocumentFragment();
- while ((index = value.indexOf('\n')) > -1) {
+ while ((index = value.indexOf("\n")) > -1) {
contents.append(
doc.createTextNode(value.slice(0, index))
);
- contents.append(createElement('BR'));
+ contents.append(createElement("BR"));
value = value.slice(index + 1);
}
node.before(contents);
@@ -3590,11 +3595,11 @@ class Squire
return frag;
}, range).focus();
}
- return this.changeFormat(null, { tag: 'CODE' }, range);
+ return this.changeFormat(null, { tag: "CODE" }, range);
}
toggleCode() {
- return (this.hasFormat('PRE') || this.hasFormat('CODE'))
+ return (this.hasFormat("PRE") || this.hasFormat("CODE"))
? this.removeCode()
: this.code();
}
@@ -3611,7 +3616,7 @@ class Squire
// --- Formatting ---
setStyle(style) {
- this.setAttribute('style', style);
+ this.setAttribute("style", style);
}
setAttribute(name, value) {
@@ -3619,7 +3624,7 @@ class Squire
let start = range?.startContainer || {};
let end = range ? range.endContainer : 0;
// When the selection is all the text inside an element, set style on the element itself
- if ('dir' == name || (isTextNode(start) && 0 === range.startOffset && start === end && end.length === range.endOffset)) {
+ if ("dir" == name || (isTextNode(start) && 0 === range.startOffset && start === end && end.length === range.endOffset)) {
this.saveUndoState(range);
setAttributes(start.parentNode, {[name]: value});
this.setRange(range);
@@ -3627,7 +3632,7 @@ class Squire
// Else create a span element
else {
this.changeFormat({
- tag: 'SPAN',
+ tag: "SPAN",
attributes: {[name]: value}
}, null, range);
}
@@ -3638,9 +3643,9 @@ class Squire
changeIndentationLevel(direction) {
let parent = this.getSelectionClosest('UL,OL,BLOCKQUOTE');
- if (parent || 'increase' === direction) {
- let method = (!parent || 'BLOCKQUOTE' === parent.nodeName) ? 'Quote' : 'List';
- this[direction + method + 'Level']();
+ if (parent || "increase" === direction) {
+ let method = (!parent || "BLOCKQUOTE" === parent.nodeName) ? "Quote" : "List";
+ this[direction + method + "Level"]();
}
}