all files / es6/modules/ spacePreserve.js

100% Statements 17/17
100% Branches 18/18
100% Functions 2/2
100% Lines 17/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28   470× 470× 470× 66352× 6063×   66352× 15678× 785×   15678×     50674×   66352× 7762× 7762× 7762×   66352×        
const spacePreserve = {
	postparse: function (parsed) {
		let chunk = [];
		let inChunk = false;
		return parsed.reduce(function (parsed, part) {
			if (part.type === "tag" && part.position === "start" && part.text && part.value === "<w:t>") {
				inChunk = true;
			}
			if (inChunk) {
				if (part.type === "placeholder" && !part.module) {
					chunk[0].value = '<w:t xml:space="preserve">';
				}
				chunk.push(part);
			}
			else {
				parsed.push(part);
			}
			if (part.type === "tag" && part.position === "end" && part.text && part.value === "</w:t>") {
				Array.prototype.push.apply(parsed, chunk);
				inChunk = false;
				chunk = [];
			}
			return parsed;
		}, []).concat(chunk);
	},
};
module.exports = spacePreserve;