all files / es6/modules/ space-preserve.js

100% Statements 21/21
100% Branches 18/18
100% Functions 2/2
100% Lines 20/20
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 29 30 31 32     179× 179× 179× 4529× 503×   4529× 1441× 146×   1441×     3088×   4529× 577× 577× 577×   4529×   179× 179×     85×  
const wrapper = require("../module-wrapper");
const spacePreserve = {
	name: "SpacePreserveModule",
	postparse(parsed) {
		let chunk = [];
		let inChunk = false;
		const result = 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;
		}, []);
		Array.prototype.push.apply(result, chunk);
		return result;
	},
};
module.exports = () => wrapper(spacePreserve);