mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 08:26:16 -04:00
lint: src/node/utils/ExportTxt.js
This commit is contained in:
parent
bfabe7c297
commit
9fff82e370
1 changed files with 23 additions and 20 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
'use strict';
|
||||||
/**
|
/**
|
||||||
* TXT export
|
* TXT export
|
||||||
*/
|
*/
|
||||||
|
@ -18,15 +19,15 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Changeset = require('ep_etherpad-lite/static/js/Changeset');
|
const Changeset = require('../../static/js/Changeset');
|
||||||
const padManager = require('../db/PadManager');
|
const padManager = require('../db/PadManager');
|
||||||
const _analyzeLine = require('./ExportHelper')._analyzeLine;
|
const _analyzeLine = require('./ExportHelper')._analyzeLine;
|
||||||
|
|
||||||
// This is slightly different than the HTML method as it passes the output to getTXTFromAText
|
// This is slightly different than the HTML method as it passes the output to getTXTFromAText
|
||||||
const getPadTXT = async function (pad, revNum) {
|
const getPadTXT = async (pad, revNum) => {
|
||||||
let atext = pad.atext;
|
let atext = pad.atext;
|
||||||
|
|
||||||
if (revNum != undefined) {
|
if (revNum !== undefined) {
|
||||||
// fetch revision atext
|
// fetch revision atext
|
||||||
atext = await pad.getInternalRevisionAText(revNum);
|
atext = await pad.getInternalRevisionAText(revNum);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +38,7 @@ const getPadTXT = async function (pad, revNum) {
|
||||||
|
|
||||||
// This is different than the functionality provided in ExportHtml as it provides formatting
|
// This is different than the functionality provided in ExportHtml as it provides formatting
|
||||||
// functionality that is designed specifically for TXT exports
|
// functionality that is designed specifically for TXT exports
|
||||||
function getTXTFromAtext(pad, atext, authorColors) {
|
const getTXTFromAtext = (pad, atext, authorColors) => {
|
||||||
const apool = pad.apool();
|
const apool = pad.apool();
|
||||||
const textLines = atext.text.slice(0, -1).split('\n');
|
const textLines = atext.text.slice(0, -1).split('\n');
|
||||||
const attribLines = Changeset.splitAttributionLines(atext.attribs, atext.text);
|
const attribLines = Changeset.splitAttributionLines(atext.attribs, atext.text);
|
||||||
|
@ -53,7 +54,7 @@ function getTXTFromAtext(pad, atext, authorColors) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function getLineTXT(text, attribs) {
|
const getLineTXT = (text, attribs) => {
|
||||||
const propVals = [false, false, false];
|
const propVals = [false, false, false];
|
||||||
const ENTER = 1;
|
const ENTER = 1;
|
||||||
const STAY = 2;
|
const STAY = 2;
|
||||||
|
@ -69,7 +70,7 @@ function getTXTFromAtext(pad, atext, authorColors) {
|
||||||
|
|
||||||
let idx = 0;
|
let idx = 0;
|
||||||
|
|
||||||
function processNextChars(numChars) {
|
const processNextChars = (numChars) => {
|
||||||
if (numChars <= 0) {
|
if (numChars <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +80,7 @@ function getTXTFromAtext(pad, atext, authorColors) {
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
const o = iter.next();
|
const o = iter.next();
|
||||||
var propChanged = false;
|
let propChanged = false;
|
||||||
|
|
||||||
Changeset.eachAttribNumber(o.attribs, (a) => {
|
Changeset.eachAttribNumber(o.attribs, (a) => {
|
||||||
if (a in anumMap) {
|
if (a in anumMap) {
|
||||||
|
@ -94,7 +95,7 @@ function getTXTFromAtext(pad, atext, authorColors) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var i = 0; i < propVals.length; i++) {
|
for (let i = 0; i < propVals.length; i++) {
|
||||||
if (propVals[i] === true) {
|
if (propVals[i] === true) {
|
||||||
propVals[i] = LEAVE;
|
propVals[i] = LEAVE;
|
||||||
propChanged = true;
|
propChanged = true;
|
||||||
|
@ -110,7 +111,7 @@ function getTXTFromAtext(pad, atext, authorColors) {
|
||||||
// leaving bold (e.g.) also leaves italics, etc.
|
// leaving bold (e.g.) also leaves italics, etc.
|
||||||
let left = false;
|
let left = false;
|
||||||
|
|
||||||
for (var i = 0; i < propVals.length; i++) {
|
for (let i = 0; i < propVals.length; i++) {
|
||||||
const v = propVals[i];
|
const v = propVals[i];
|
||||||
|
|
||||||
if (!left) {
|
if (!left) {
|
||||||
|
@ -123,9 +124,9 @@ function getTXTFromAtext(pad, atext, authorColors) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tags2close = [];
|
const tags2close = [];
|
||||||
|
|
||||||
for (var i = propVals.length - 1; i >= 0; i--) {
|
for (let i = propVals.length - 1; i >= 0; i--) {
|
||||||
if (propVals[i] === LEAVE) {
|
if (propVals[i] === LEAVE) {
|
||||||
// emitCloseTag(i);
|
// emitCloseTag(i);
|
||||||
tags2close.push(i);
|
tags2close.push(i);
|
||||||
|
@ -136,7 +137,7 @@ function getTXTFromAtext(pad, atext, authorColors) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < propVals.length; i++) {
|
for (let i = 0; i < propVals.length; i++) {
|
||||||
if (propVals[i] === ENTER || propVals[i] === STAY) {
|
if (propVals[i] === ENTER || propVals[i] === STAY) {
|
||||||
propVals[i] = true;
|
propVals[i] = true;
|
||||||
}
|
}
|
||||||
|
@ -163,18 +164,20 @@ function getTXTFromAtext(pad, atext, authorColors) {
|
||||||
assem.append(s);
|
assem.append(s);
|
||||||
} // end iteration over spans in line
|
} // end iteration over spans in line
|
||||||
|
|
||||||
var tags2close = [];
|
const tags2close = [];
|
||||||
for (var i = propVals.length - 1; i >= 0; i--) {
|
for (let i = propVals.length - 1; i >= 0; i--) {
|
||||||
if (propVals[i]) {
|
if (propVals[i]) {
|
||||||
tags2close.push(i);
|
tags2close.push(i);
|
||||||
propVals[i] = false;
|
propVals[i] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // end processNextChars
|
};
|
||||||
|
// end processNextChars
|
||||||
|
|
||||||
processNextChars(text.length - idx);
|
processNextChars(text.length - idx);
|
||||||
return (assem.toString());
|
return (assem.toString());
|
||||||
} // end getLineHTML
|
};
|
||||||
|
// end getLineHTML
|
||||||
|
|
||||||
const pieces = [css];
|
const pieces = [css];
|
||||||
|
|
||||||
|
@ -193,7 +196,7 @@ function getTXTFromAtext(pad, atext, authorColors) {
|
||||||
const line = _analyzeLine(textLines[i], attribLines[i], apool);
|
const line = _analyzeLine(textLines[i], attribLines[i], apool);
|
||||||
let lineContent = getLineTXT(line.text, line.aline);
|
let lineContent = getLineTXT(line.text, line.aline);
|
||||||
|
|
||||||
if (line.listTypeName == 'bullet') {
|
if (line.listTypeName === 'bullet') {
|
||||||
lineContent = `* ${lineContent}`; // add a bullet
|
lineContent = `* ${lineContent}`; // add a bullet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +215,7 @@ function getTXTFromAtext(pad, atext, authorColors) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.listTypeName == 'number') {
|
if (line.listTypeName === 'number') {
|
||||||
/*
|
/*
|
||||||
* listLevel == amount of indentation
|
* listLevel == amount of indentation
|
||||||
* listNumber(s) == item number
|
* listNumber(s) == item number
|
||||||
|
@ -249,11 +252,11 @@ function getTXTFromAtext(pad, atext, authorColors) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return pieces.join('');
|
return pieces.join('');
|
||||||
}
|
};
|
||||||
|
|
||||||
exports.getTXTFromAtext = getTXTFromAtext;
|
exports.getTXTFromAtext = getTXTFromAtext;
|
||||||
|
|
||||||
exports.getPadTXTDocument = async function (padId, revNum) {
|
exports.getPadTXTDocument = async (padId, revNum) => {
|
||||||
const pad = await padManager.getPad(padId);
|
const pad = await padManager.getPad(padId);
|
||||||
return getPadTXT(pad, revNum);
|
return getPadTXT(pad, revNum);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue