@polotno/pdf-export 0.1.25 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/text.js +35 -12
- package/package.json +1 -1
package/lib/text.js
CHANGED
|
@@ -277,11 +277,23 @@ function serializeAttributes(attributes) {
|
|
|
277
277
|
.map(([key, value]) => value === '' ? key : `${key}="${value.replace(/"/g, '"')}"`)
|
|
278
278
|
.join(' '));
|
|
279
279
|
}
|
|
280
|
+
function shouldSkipNode(node) {
|
|
281
|
+
if (node.type === 'element' && node.tagName === 'span') {
|
|
282
|
+
const classAttr = node.attributes['class'] || node.attributes['className'] || '';
|
|
283
|
+
if (/\bql-cursor\b/.test(classAttr)) {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
280
289
|
function serializeNodes(nodes) {
|
|
281
290
|
return nodes
|
|
282
291
|
.map((node) => {
|
|
292
|
+
if (shouldSkipNode(node)) {
|
|
293
|
+
return '';
|
|
294
|
+
}
|
|
283
295
|
if (node.type === 'text') {
|
|
284
|
-
return node.content;
|
|
296
|
+
return node.content.replace(/\uFEFF/g, '');
|
|
285
297
|
}
|
|
286
298
|
const attrs = serializeAttributes(node.attributes);
|
|
287
299
|
if (VOID_ELEMENTS.has(node.tagName)) {
|
|
@@ -325,23 +337,34 @@ function nodesToParagraphs(nodes, baseIndentLevel = 0) {
|
|
|
325
337
|
pendingInline = [];
|
|
326
338
|
};
|
|
327
339
|
for (const node of nodes) {
|
|
340
|
+
if (shouldSkipNode(node)) {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
328
343
|
if (node.type === 'text') {
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
344
|
+
const newlineRegex = /\n+/g;
|
|
345
|
+
let lastIndex = 0;
|
|
346
|
+
let match;
|
|
347
|
+
while ((match = newlineRegex.exec(node.content)) !== null) {
|
|
348
|
+
const chunk = node.content.slice(lastIndex, match.index);
|
|
349
|
+
if (chunk.length > 0) {
|
|
334
350
|
pendingInline.push({
|
|
335
351
|
type: 'text',
|
|
336
|
-
content:
|
|
352
|
+
content: chunk,
|
|
337
353
|
});
|
|
338
354
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
355
|
+
flushInline();
|
|
356
|
+
const extraBreaks = match[0].length - 1;
|
|
357
|
+
for (let extra = 0; extra < extraBreaks; extra++) {
|
|
358
|
+
paragraphs.push({ html: '' });
|
|
344
359
|
}
|
|
360
|
+
lastIndex = newlineRegex.lastIndex;
|
|
361
|
+
}
|
|
362
|
+
const rest = node.content.slice(lastIndex);
|
|
363
|
+
if (rest.length > 0) {
|
|
364
|
+
pendingInline.push({
|
|
365
|
+
type: 'text',
|
|
366
|
+
content: rest,
|
|
367
|
+
});
|
|
345
368
|
}
|
|
346
369
|
continue;
|
|
347
370
|
}
|