sr-npm 1.7.1249 → 1.7.1253
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.
|
@@ -137,7 +137,8 @@ async function htmlRichContentConverter(sections,richContentConverterToken) {
|
|
|
137
137
|
);
|
|
138
138
|
if (response.ok) {
|
|
139
139
|
const data = await response.json();
|
|
140
|
-
|
|
140
|
+
// const richContentWithSpacing=addSpacingToRichContent(sectionData.text,data.richContent.richContent);
|
|
141
|
+
const richContentWithSpacing=addEmptyParagraphsBetweenConsecutive(sectionData.text,data.richContent.richContent);
|
|
141
142
|
richContentObject[sectionTitle] = richContentWithSpacing
|
|
142
143
|
}
|
|
143
144
|
else {
|
|
@@ -162,6 +163,8 @@ function addSpacingToRichContent(html, richContent) {
|
|
|
162
163
|
const htmlParagraphsWithBr = new Map(); // text -> array of parts split by <br>
|
|
163
164
|
// Check if HTML has consecutive paragraphs (</p><p> pattern)
|
|
164
165
|
const hasConsecutiveParagraphs = /<\/p>\s*<p/i.test(html);
|
|
166
|
+
// Check if HTML has paragraph followed by list (</p><ul> pattern)
|
|
167
|
+
const hasParagraphBeforeList = /<\/p>\s*<ul/i.test(html);
|
|
165
168
|
|
|
166
169
|
const pTagRegex = /<p>(.*?)<\/p>/gi;
|
|
167
170
|
let match;
|
|
@@ -215,6 +218,11 @@ function addSpacingToRichContent(html, richContent) {
|
|
|
215
218
|
return true;
|
|
216
219
|
}
|
|
217
220
|
|
|
221
|
+
// If HTML has </p><ul> and next node is a list, add spacing
|
|
222
|
+
if (hasParagraphBeforeList && nextNode && nextNode.type === 'BULLETED_LIST') {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
|
|
218
226
|
const text = node.nodes?.[0]?.textData?.text || '';
|
|
219
227
|
const trimmedText = text.trim();
|
|
220
228
|
|
|
@@ -322,6 +330,43 @@ function createEmptyParagraph(id) {
|
|
|
322
330
|
};
|
|
323
331
|
}
|
|
324
332
|
|
|
333
|
+
// Adds empty paragraph nodes between consecutive paragraphs and before lists
|
|
334
|
+
function addEmptyParagraphsBetweenConsecutive(html, richContent) {
|
|
335
|
+
if (!richContent || !richContent.nodes) return richContent;
|
|
336
|
+
|
|
337
|
+
const hasConsecutiveParagraphs = /<\/p>\s*<p/i.test(html);
|
|
338
|
+
const hasParagraphBeforeList = /<\/p>\s*<ul/i.test(html);
|
|
339
|
+
|
|
340
|
+
if (!hasConsecutiveParagraphs && !hasParagraphBeforeList) return richContent;
|
|
341
|
+
|
|
342
|
+
const nodes = richContent.nodes;
|
|
343
|
+
const newNodes = [];
|
|
344
|
+
let nodeIdCounter = 0;
|
|
345
|
+
|
|
346
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
347
|
+
const currentNode = nodes[i];
|
|
348
|
+
const nextNode = nodes[i + 1];
|
|
349
|
+
|
|
350
|
+
newNodes.push(currentNode);
|
|
351
|
+
|
|
352
|
+
if (currentNode.type === 'PARAGRAPH' && nextNode) {
|
|
353
|
+
// Add empty paragraph between consecutive paragraphs
|
|
354
|
+
if (hasConsecutiveParagraphs && nextNode.type === 'PARAGRAPH') {
|
|
355
|
+
newNodes.push(createEmptyParagraph(`empty_consecutive_${nodeIdCounter++}`));
|
|
356
|
+
}
|
|
357
|
+
// Add empty paragraph before list
|
|
358
|
+
if (hasParagraphBeforeList && nextNode.type === 'BULLETED_LIST') {
|
|
359
|
+
newNodes.push(createEmptyParagraph(`empty_before_list_${nodeIdCounter++}`));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return {
|
|
365
|
+
...richContent,
|
|
366
|
+
nodes: newNodes
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
325
370
|
|
|
326
371
|
|
|
327
372
|
|