mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
lint: contentcollector and domline
Various tidy up and linting of contentcollector.js and domline.js. 3 Tests disabled which are not due to be covered. Co-authored-by: Richard Hansen <rhansen@rhansen.org>
This commit is contained in:
parent
10a91825fc
commit
f0a77cb98c
3 changed files with 187 additions and 206 deletions
|
@ -26,17 +26,17 @@ const Security = require('./security');
|
|||
const hooks = require('./pluginfw/hooks');
|
||||
const _ = require('./underscore');
|
||||
const lineAttributeMarker = require('./linestylefilter').lineAttributeMarker;
|
||||
const noop = function () {};
|
||||
const noop = () => {};
|
||||
|
||||
|
||||
const domline = {};
|
||||
|
||||
domline.addToLineClass = function (lineClass, cls) {
|
||||
domline.addToLineClass = (lineClass, cls) => {
|
||||
// an "empty span" at any point can be used to add classes to
|
||||
// the line, using line:className. otherwise, we ignore
|
||||
// the span.
|
||||
cls.replace(/\S+/g, (c) => {
|
||||
if (c.indexOf('line:') == 0) {
|
||||
if (c.indexOf('line:') === 0) {
|
||||
// add class to line
|
||||
lineClass = (lineClass ? `${lineClass} ` : '') + c.substring(5);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ domline.addToLineClass = function (lineClass, cls) {
|
|||
|
||||
// if "document" is falsy we don't create a DOM node, just
|
||||
// an object with innerHTML and className
|
||||
domline.createDomLine = function (nonEmpty, doesWrap, optBrowser, optDocument) {
|
||||
domline.createDomLine = (nonEmpty, doesWrap, optBrowser, optDocument) => {
|
||||
const result = {
|
||||
node: null,
|
||||
appendSpan: noop,
|
||||
|
@ -73,15 +73,12 @@ domline.createDomLine = function (nonEmpty, doesWrap, optBrowser, optDocument) {
|
|||
let postHtml = '';
|
||||
let curHTML = null;
|
||||
|
||||
function processSpaces(s) {
|
||||
return domline.processSpaces(s, doesWrap);
|
||||
}
|
||||
|
||||
const processSpaces = (s) => domline.processSpaces(s, doesWrap);
|
||||
const perTextNodeProcess = (doesWrap ? _.identity : processSpaces);
|
||||
const perHtmlLineProcess = (doesWrap ? processSpaces : _.identity);
|
||||
let lineClass = 'ace-line';
|
||||
|
||||
result.appendSpan = function (txt, cls) {
|
||||
result.appendSpan = (txt, cls) => {
|
||||
let processedMarker = false;
|
||||
// Handle lineAttributeMarker, if present
|
||||
if (cls.indexOf(lineAttributeMarker) >= 0) {
|
||||
|
@ -96,7 +93,6 @@ domline.createDomLine = function (nonEmpty, doesWrap, optBrowser, optDocument) {
|
|||
postHtml += modifier.postHtml;
|
||||
processedMarker |= modifier.processedMarker;
|
||||
});
|
||||
|
||||
if (listType) {
|
||||
listType = listType[1];
|
||||
if (listType) {
|
||||
|
@ -105,12 +101,15 @@ domline.createDomLine = function (nonEmpty, doesWrap, optBrowser, optDocument) {
|
|||
postHtml = `</li></ul>${postHtml}`;
|
||||
} else {
|
||||
if (start) { // is it a start of a list with more than one item in?
|
||||
if (start[1] == 1) { // if its the first one at this level?
|
||||
lineClass = `${lineClass} ` + `list-start-${listType}`; // Add start class to DIV node
|
||||
if (start[1] === 1) { // if its the first one at this level?
|
||||
// Add start class to DIV node
|
||||
lineClass = `${lineClass} ` + `list-start-${listType}`;
|
||||
}
|
||||
preHtml += `<ol start=${start[1]} class="list-${Security.escapeHTMLAttribute(listType)}"><li>`;
|
||||
preHtml +=
|
||||
`<ol start=${start[1]} class="list-${Security.escapeHTMLAttribute(listType)}"><li>`;
|
||||
} else {
|
||||
preHtml += `<ol class="list-${Security.escapeHTMLAttribute(listType)}"><li>`; // Handles pasted contents into existing lists
|
||||
// Handles pasted contents into existing lists
|
||||
preHtml += `<ol class="list-${Security.escapeHTMLAttribute(listType)}"><li>`;
|
||||
}
|
||||
postHtml += '</li></ol>';
|
||||
}
|
||||
|
@ -163,18 +162,20 @@ domline.createDomLine = function (nonEmpty, doesWrap, optBrowser, optDocument) {
|
|||
} else if (txt) {
|
||||
if (href) {
|
||||
const urn_schemes = new RegExp('^(about|geo|mailto|tel):');
|
||||
if (!~href.indexOf('://') && !urn_schemes.test(href)) // if the url doesn't include a protocol prefix, assume http
|
||||
{
|
||||
// if the url doesn't include a protocol prefix, assume http
|
||||
if (!~href.indexOf('://') && !urn_schemes.test(href)) {
|
||||
href = `http://${href}`;
|
||||
}
|
||||
// Using rel="noreferrer" stops leaking the URL/location of the pad when clicking links in the document.
|
||||
// Using rel="noreferrer" stops leaking the URL/location of the pad when
|
||||
// clicking links in the document.
|
||||
// Not all browsers understand this attribute, but it's part of the HTML5 standard.
|
||||
// https://html.spec.whatwg.org/multipage/links.html#link-type-noreferrer
|
||||
// Additionally, we do rel="noopener" to ensure a higher level of referrer security.
|
||||
// https://html.spec.whatwg.org/multipage/links.html#link-type-noopener
|
||||
// https://mathiasbynens.github.io/rel-noopener/
|
||||
// https://github.com/ether/etherpad-lite/pull/3636
|
||||
extraOpenTags = `${extraOpenTags}<a href="${Security.escapeHTMLAttribute(href)}" rel="noreferrer noopener">`;
|
||||
const escapedHref = Security.escapeHTMLAttribute(href);
|
||||
extraOpenTags = `${extraOpenTags}<a href="${escapedHref}" rel="noreferrer noopener">`;
|
||||
extraCloseTags = `</a>${extraCloseTags}`;
|
||||
}
|
||||
if (simpleTags) {
|
||||
|
@ -183,16 +184,22 @@ domline.createDomLine = function (nonEmpty, doesWrap, optBrowser, optDocument) {
|
|||
simpleTags.reverse();
|
||||
extraCloseTags = `</${simpleTags.join('></')}>${extraCloseTags}`;
|
||||
}
|
||||
html.push('<span class="', Security.escapeHTMLAttribute(cls || ''), '">', extraOpenTags, perTextNodeProcess(Security.escapeHTML(txt)), extraCloseTags, '</span>');
|
||||
html.push(
|
||||
'<span class="', Security.escapeHTMLAttribute(cls || ''),
|
||||
'">',
|
||||
extraOpenTags,
|
||||
perTextNodeProcess(Security.escapeHTML(txt)),
|
||||
extraCloseTags,
|
||||
'</span>');
|
||||
}
|
||||
};
|
||||
result.clearSpans = function () {
|
||||
result.clearSpans = () => {
|
||||
html = [];
|
||||
lineClass = 'ace-line';
|
||||
result.lineMarker = 0;
|
||||
};
|
||||
|
||||
function writeHTML() {
|
||||
const writeHTML = () => {
|
||||
let newHTML = perHtmlLineProcess(html.join(''));
|
||||
if (!newHTML) {
|
||||
if ((!document) || (!optBrowser)) {
|
||||
|
@ -209,21 +216,19 @@ domline.createDomLine = function (nonEmpty, doesWrap, optBrowser, optDocument) {
|
|||
curHTML = newHTML;
|
||||
result.node.innerHTML = curHTML;
|
||||
}
|
||||
if (lineClass !== null) result.node.className = lineClass;
|
||||
if (lineClass != null) result.node.className = lineClass;
|
||||
|
||||
hooks.callAll('acePostWriteDomLineHTML', {
|
||||
node: result.node,
|
||||
});
|
||||
}
|
||||
};
|
||||
result.prepareForAdd = writeHTML;
|
||||
result.finishUpdate = writeHTML;
|
||||
result.getInnerHTML = function () {
|
||||
return curHTML || '';
|
||||
};
|
||||
result.getInnerHTML = () => curHTML || '';
|
||||
return result;
|
||||
};
|
||||
|
||||
domline.processSpaces = function (s, doesWrap) {
|
||||
domline.processSpaces = (s, doesWrap) => {
|
||||
if (s.indexOf('<') < 0 && !doesWrap) {
|
||||
// short-cut
|
||||
return s.replace(/ /g, ' ');
|
||||
|
@ -237,31 +242,31 @@ domline.processSpaces = function (s, doesWrap) {
|
|||
let beforeSpace = false;
|
||||
// last space in a run is normal, others are nbsp,
|
||||
// end of line is nbsp
|
||||
for (var i = parts.length - 1; i >= 0; i--) {
|
||||
var p = parts[i];
|
||||
if (p == ' ') {
|
||||
for (let i = parts.length - 1; i >= 0; i--) {
|
||||
const p = parts[i];
|
||||
if (p === ' ') {
|
||||
if (endOfLine || beforeSpace) parts[i] = ' ';
|
||||
endOfLine = false;
|
||||
beforeSpace = true;
|
||||
} else if (p.charAt(0) != '<') {
|
||||
} else if (p.charAt(0) !== '<') {
|
||||
endOfLine = false;
|
||||
beforeSpace = false;
|
||||
}
|
||||
}
|
||||
// beginning of line is nbsp
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
var p = parts[i];
|
||||
if (p == ' ') {
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const p = parts[i];
|
||||
if (p === ' ') {
|
||||
parts[i] = ' ';
|
||||
break;
|
||||
} else if (p.charAt(0) != '<') {
|
||||
} else if (p.charAt(0) !== '<') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
var p = parts[i];
|
||||
if (p == ' ') {
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const p = parts[i];
|
||||
if (p === ' ') {
|
||||
parts[i] = ' ';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue