eat-js-sdk 2.3.6 → 2.3.7

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.
@@ -19420,9 +19420,10 @@ const parseWords = (rawText) => {
19420
19420
  const segments = [];
19421
19421
  let globalIndex = 0;
19422
19422
  const tokenRegex = /((?:<(?!\/?eat-)[^>]+>)*)<eat-contentful>(.*?)<\/eat-contentful>((?:<\/[^>]+>)*)|((?:<(?!\/?eat-)[^>]*>|[^<>])+)/g;
19423
- const trailingPunctRe = /([.,!?;:)\]}"'\u201D\u2019»…\u2014\u2013]+)$/;
19424
- const leadingPunctRe = /^([([{'""\u201C\u2018]+)/;
19425
- const purePunctRe = /^[^\w\u00C0-\u024F]+$/;
19423
+ const trailingPunctuationPattern = /([.,!?;:)\]}"'\u201D\u2019»…\u2014\u2013]+)$/;
19424
+ const leadingPunctuationPattern = /^([([{'""\u201C\u2018]+)/;
19425
+ const openingCharsAtWordEndPattern = /([(\[{\u201C\u2018]+)$/;
19426
+ const wordContainsOnlyPunctuationPattern = /^[^\w\u00C0-\u024F]+$/;
19426
19427
  for (let pIdx = 0; pIdx < paragraphs.length; pIdx++) {
19427
19428
  const para = paragraphs[pIdx];
19428
19429
  const decoded = para.replace(/&lt;eat-contentful&gt;/g, "<eat-contentful>").replace(/&lt;\/eat-contentful&gt;/g, "</eat-contentful>");
@@ -19430,7 +19431,7 @@ const parseWords = (rawText) => {
19430
19431
  let match;
19431
19432
  let pendingLeadingPunct = "";
19432
19433
  const flushLeadingPunct = (text) => {
19433
- const m = text.match(leadingPunctRe);
19434
+ const m = text.match(leadingPunctuationPattern);
19434
19435
  const extractedLeading = m ? m[1] : "";
19435
19436
  const lp = pendingLeadingPunct + extractedLeading;
19436
19437
  const leadingPunctuation = lp.length ? lp : void 0;
@@ -19447,7 +19448,7 @@ const parseWords = (rawText) => {
19447
19448
  const { leadingPunctuation, extractedLeading } = flushLeadingPunct(displayText);
19448
19449
  const textAfterLeading = extractedLeading ? displayText.slice(extractedLeading.length) : displayText;
19449
19450
  const rawAfterLeading = extractedLeading ? rawContent.slice(extractedLeading.length) : rawContent;
19450
- const punctMatch = textAfterLeading.match(trailingPunctRe);
19451
+ const punctMatch = textAfterLeading.match(trailingPunctuationPattern);
19451
19452
  const rawText2 = punctMatch ? rawAfterLeading.slice(0, -punctMatch[1].length) : rawAfterLeading;
19452
19453
  const trailingPunctuation = punctMatch ? punctMatch[1] : void 0;
19453
19454
  const innerText = punctMatch ? textAfterLeading.slice(0, -punctMatch[1].length) : textAfterLeading;
@@ -19461,8 +19462,8 @@ const parseWords = (rawText) => {
19461
19462
  const words = hasHtmlTags(rawChunk) ? extractHtmlWords(rawChunk) : rawChunk.split(/\s+/).filter(Boolean);
19462
19463
  for (const word of words) {
19463
19464
  const visibleWord = hasHtmlTags(word) ? stripTags(word) : decodeHtmlEntities(word);
19464
- if (purePunctRe.test(visibleWord)) {
19465
- if (leadingPunctRe.test(visibleWord)) {
19465
+ if (wordContainsOnlyPunctuationPattern.test(visibleWord)) {
19466
+ if (leadingPunctuationPattern.test(visibleWord)) {
19466
19467
  pendingLeadingPunct += visibleWord;
19467
19468
  } else {
19468
19469
  const prev = segments[segments.length - 1];
@@ -19482,7 +19483,7 @@ const parseWords = (rawText) => {
19482
19483
  wordForTrailing = word.replace(new RegExp("^((?:<[^>]+>)*)" + escapeRegExp(extractedLeading)), "$1");
19483
19484
  }
19484
19485
  const visibleAfterLeading = extractedLeading ? innerVisible.slice(extractedLeading.length) : innerVisible;
19485
- const punctMatch = visibleAfterLeading.match(trailingPunctRe);
19486
+ const punctMatch = visibleAfterLeading.match(trailingPunctuationPattern);
19486
19487
  if (punctMatch) {
19487
19488
  const punc = punctMatch[1];
19488
19489
  const rebuilt = wordForTrailing.replace(new RegExp(escapeRegExp(punc) + "(</)"), "$1");
@@ -19497,8 +19498,14 @@ const parseWords = (rawText) => {
19497
19498
  }
19498
19499
  } else {
19499
19500
  const { leadingPunctuation, extractedLeading } = flushLeadingPunct(visibleWord);
19500
- const wordAfterLeading = extractedLeading ? visibleWord.slice(extractedLeading.length) : visibleWord;
19501
- const punctMatch = wordAfterLeading.match(trailingPunctRe);
19501
+ let wordAfterLeading = extractedLeading ? visibleWord.slice(extractedLeading.length) : visibleWord;
19502
+ const openingCharsAtEnd = wordAfterLeading.match(openingCharsAtWordEndPattern);
19503
+ if (openingCharsAtEnd) {
19504
+ pendingLeadingPunct += openingCharsAtEnd[1];
19505
+ wordAfterLeading = wordAfterLeading.slice(0, -openingCharsAtEnd[1].length);
19506
+ }
19507
+ if (!wordAfterLeading.length) continue;
19508
+ const punctMatch = wordAfterLeading.match(trailingPunctuationPattern);
19502
19509
  const text = decodeNbsp(punctMatch ? wordAfterLeading.slice(0, -punctMatch[1].length) : wordAfterLeading);
19503
19510
  const trailingPunctuation = punctMatch ? punctMatch[1] : void 0;
19504
19511
  segments.push({ id: `${globalIndex}`, text, leadingPunctuation, trailingPunctuation });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eat-js-sdk",
3
- "version": "2.3.6",
3
+ "version": "2.3.7",
4
4
  "change version": "2.3.0",
5
5
  "description": "Authoring tool frontend SDK",
6
6
  "contributors": [