eat-js-sdk 2.2.8 → 2.2.9

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.
@@ -19098,31 +19098,69 @@ const decodeNbsp = (text) => text.replace(/ /g, " ").replace(/ /g,
19098
19098
  const stripTags = (s) => s.replace(/<[^>]+>/g, "");
19099
19099
  const hasHtmlTags = (s) => /<[^>]/.test(s);
19100
19100
  const getTagName = (tag) => tag.replace(/^<\/?([^\s>]+).*$/, "$1").toLowerCase();
19101
+ const isSuperSubTag = (tag) => {
19102
+ const name = getTagName(tag);
19103
+ return name === "sup" || name === "sub";
19104
+ };
19101
19105
  const extractHtmlWords = (htmlText) => {
19102
- const re = /(<\/[^>]+>)|(<[^>]+>)|([^\s<>]+)/g;
19106
+ const re = /(\s+)|(<\/[^>]+>)|(<[^>]+>)|([^\s<>]+)/g;
19103
19107
  const tokens = [];
19104
19108
  let m;
19105
19109
  while ((m = re.exec(htmlText)) !== null) {
19106
- if (m[1]) tokens.push({ type: "close", value: m[1] });
19107
- else if (m[2]) tokens.push({ type: "open", value: m[2] });
19108
- else tokens.push({ type: "word", value: m[3] });
19110
+ if (m[1]) tokens.push({ type: "space", value: m[1] });
19111
+ else if (m[2]) tokens.push({ type: "close", value: m[2] });
19112
+ else if (m[3]) tokens.push({ type: "open", value: m[3] });
19113
+ else tokens.push({ type: "word", value: m[4] });
19109
19114
  }
19110
19115
  const words = [];
19111
19116
  const openStack = [];
19112
- for (const tok of tokens) {
19117
+ let lastWasSpace = true;
19118
+ let mergingIntoLast = false;
19119
+ let mergeDepth = 0;
19120
+ for (let i = 0; i < tokens.length; i++) {
19121
+ const tok = tokens[i];
19122
+ if (tok.type === "space") {
19123
+ lastWasSpace = true;
19124
+ continue;
19125
+ }
19113
19126
  if (tok.type === "open") {
19114
- openStack.push(tok.value);
19115
- } else if (tok.type === "close") {
19116
- const closingName = getTagName(tok.value);
19117
- for (let i = openStack.length - 1; i >= 0; i--) {
19118
- if (getTagName(openStack[i]) === closingName) {
19119
- openStack.splice(i, 1);
19120
- break;
19127
+ if (!lastWasSpace && isSuperSubTag(tok.value) && words.length > 0) {
19128
+ mergingIntoLast = true;
19129
+ mergeDepth = 1;
19130
+ words[words.length - 1].value += tok.value;
19131
+ } else if (mergingIntoLast) {
19132
+ mergeDepth++;
19133
+ words[words.length - 1].value += tok.value;
19134
+ } else {
19135
+ openStack.push(tok.value);
19136
+ }
19137
+ continue;
19138
+ }
19139
+ if (tok.type === "close") {
19140
+ if (mergingIntoLast) {
19141
+ words[words.length - 1].value += tok.value;
19142
+ mergeDepth--;
19143
+ if (mergeDepth <= 0) {
19144
+ mergingIntoLast = false;
19145
+ mergeDepth = 0;
19146
+ }
19147
+ } else {
19148
+ const closingName = getTagName(tok.value);
19149
+ for (let j = openStack.length - 1; j >= 0; j--) {
19150
+ if (getTagName(openStack[j]) === closingName) {
19151
+ openStack.splice(j, 1);
19152
+ break;
19153
+ }
19121
19154
  }
19122
19155
  }
19156
+ continue;
19157
+ }
19158
+ if (mergingIntoLast) {
19159
+ words[words.length - 1].value += tok.value;
19123
19160
  } else {
19124
19161
  words.push({ value: tok.value, openStack: [...openStack] });
19125
19162
  }
19163
+ lastWasSpace = false;
19126
19164
  }
19127
19165
  return words.map(({ value, openStack: openStack2 }) => {
19128
19166
  const open = openStack2.join("");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eat-js-sdk",
3
- "version": "2.2.8",
3
+ "version": "2.2.9",
4
4
  "change version": "2.2.0",
5
5
  "description": "Authoring tool frontend SDK",
6
6
  "contributors": [