@lvce-editor/chat-message-parsing-worker 1.6.0 → 1.8.0

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.
@@ -486,10 +486,10 @@ const execute = (command, ...args) => {
486
486
 
487
487
  const Two$1 = '2.0';
488
488
  const callbacks = Object.create(null);
489
- const get = id => {
489
+ const get$1 = id => {
490
490
  return callbacks[id];
491
491
  };
492
- const remove = id => {
492
+ const remove$1 = id => {
493
493
  delete callbacks[id];
494
494
  };
495
495
  class JsonRpcError extends Error {
@@ -635,14 +635,14 @@ const warn = (...args) => {
635
635
  console.warn(...args);
636
636
  };
637
637
  const resolve = (id, response) => {
638
- const fn = get(id);
638
+ const fn = get$1(id);
639
639
  if (!fn) {
640
640
  console.log(response);
641
641
  warn(`callback ${id} may already be disposed`);
642
642
  return;
643
643
  }
644
644
  fn(response);
645
- remove(id);
645
+ remove$1(id);
646
646
  };
647
647
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
648
648
  const getErrorType = prettyError => {
@@ -698,7 +698,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
698
698
  const errorProperty = getErrorProperty(error, prettyError);
699
699
  return create$1$1(id, errorProperty);
700
700
  };
701
- const create$5 = (message, result) => {
701
+ const create$8 = (message, result) => {
702
702
  return {
703
703
  id: message.id,
704
704
  jsonrpc: Two$1,
@@ -707,7 +707,7 @@ const create$5 = (message, result) => {
707
707
  };
708
708
  const getSuccessResponse = (message, result) => {
709
709
  const resultProperty = result ?? null;
710
- return create$5(message, resultProperty);
710
+ return create$8(message, resultProperty);
711
711
  };
712
712
  const getErrorResponseSimple = (id, error) => {
713
713
  return {
@@ -801,7 +801,7 @@ const handleJsonRpcMessage = async (...args) => {
801
801
 
802
802
  const Two = '2.0';
803
803
 
804
- const create$4 = (method, params) => {
804
+ const create$7 = (method, params) => {
805
805
  return {
806
806
  jsonrpc: Two,
807
807
  method,
@@ -809,7 +809,7 @@ const create$4 = (method, params) => {
809
809
  };
810
810
  };
811
811
 
812
- const create$3 = (id, method, params) => {
812
+ const create$6 = (id, method, params) => {
813
813
  const message = {
814
814
  id,
815
815
  jsonrpc: Two,
@@ -820,12 +820,12 @@ const create$3 = (id, method, params) => {
820
820
  };
821
821
 
822
822
  let id = 0;
823
- const create$2 = () => {
823
+ const create$5 = () => {
824
824
  return ++id;
825
825
  };
826
826
 
827
827
  const registerPromise = map => {
828
- const id = create$2();
828
+ const id = create$5();
829
829
  const {
830
830
  promise,
831
831
  resolve
@@ -842,7 +842,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
842
842
  id,
843
843
  promise
844
844
  } = registerPromise(callbacks);
845
- const message = create$3(id, method, params);
845
+ const message = create$6(id, method, params);
846
846
  if (useSendAndTransfer && ipc.sendAndTransfer) {
847
847
  ipc.sendAndTransfer(message);
848
848
  } else {
@@ -878,7 +878,7 @@ const createRpc = ipc => {
878
878
  * @deprecated
879
879
  */
880
880
  send(method, ...params) {
881
- const message = create$4(method, params);
881
+ const message = create$7(method, params);
882
882
  ipc.send(message);
883
883
  }
884
884
  };
@@ -918,7 +918,7 @@ const listen$1 = async (module, options) => {
918
918
  return ipc;
919
919
  };
920
920
 
921
- const create$1 = async ({
921
+ const create$4 = async ({
922
922
  commandMap,
923
923
  isMessagePortOpen = true,
924
924
  messagePort
@@ -936,7 +936,66 @@ const create$1 = async ({
936
936
  return rpc;
937
937
  };
938
938
 
939
- const create = async ({
939
+ const create$3 = async ({
940
+ commandMap,
941
+ isMessagePortOpen,
942
+ send
943
+ }) => {
944
+ const {
945
+ port1,
946
+ port2
947
+ } = new MessageChannel();
948
+ await send(port1);
949
+ return create$4({
950
+ commandMap,
951
+ isMessagePortOpen,
952
+ messagePort: port2
953
+ });
954
+ };
955
+
956
+ const createSharedLazyRpc = factory => {
957
+ let rpcPromise;
958
+ const getOrCreate = () => {
959
+ if (!rpcPromise) {
960
+ rpcPromise = factory();
961
+ }
962
+ return rpcPromise;
963
+ };
964
+ return {
965
+ async dispose() {
966
+ const rpc = await getOrCreate();
967
+ await rpc.dispose();
968
+ },
969
+ async invoke(method, ...params) {
970
+ const rpc = await getOrCreate();
971
+ return rpc.invoke(method, ...params);
972
+ },
973
+ async invokeAndTransfer(method, ...params) {
974
+ const rpc = await getOrCreate();
975
+ return rpc.invokeAndTransfer(method, ...params);
976
+ },
977
+ async send(method, ...params) {
978
+ const rpc = await getOrCreate();
979
+ rpc.send(method, ...params);
980
+ }
981
+ };
982
+ };
983
+
984
+ const create$2 = async ({
985
+ commandMap,
986
+ isMessagePortOpen,
987
+ send
988
+ }) => {
989
+ return createSharedLazyRpc(() => {
990
+ return create$3({
991
+ commandMap,
992
+ isMessagePortOpen,
993
+ send
994
+ });
995
+ });
996
+ };
997
+
998
+ const create$1 = async ({
940
999
  commandMap
941
1000
  }) => {
942
1001
  // TODO create a commandMap per rpc instance
@@ -948,13 +1007,415 @@ const create = async ({
948
1007
  };
949
1008
 
950
1009
  const handleMessagePort = async port => {
951
- await create$1({
1010
+ await create$4({
952
1011
  commandMap: commandMap,
953
1012
  isMessagePortOpen: true,
954
1013
  messagePort: port
955
1014
  });
956
1015
  };
957
1016
 
1017
+ const initialize = async (_, port) => {
1018
+ await handleMessagePort(port);
1019
+ };
1020
+
1021
+ const createMockRpc = ({
1022
+ commandMap
1023
+ }) => {
1024
+ const invocations = [];
1025
+ const invoke = (method, ...params) => {
1026
+ invocations.push([method, ...params]);
1027
+ const command = commandMap[method];
1028
+ if (!command) {
1029
+ throw new Error(`command ${method} not found`);
1030
+ }
1031
+ return command(...params);
1032
+ };
1033
+ const mockRpc = {
1034
+ invocations,
1035
+ invoke,
1036
+ invokeAndTransfer: invoke
1037
+ };
1038
+ return mockRpc;
1039
+ };
1040
+
1041
+ const rpcs = Object.create(null);
1042
+ const set$1 = (id, rpc) => {
1043
+ rpcs[id] = rpc;
1044
+ };
1045
+ const get = id => {
1046
+ return rpcs[id];
1047
+ };
1048
+ const remove = id => {
1049
+ delete rpcs[id];
1050
+ };
1051
+
1052
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1053
+ const create = rpcId => {
1054
+ return {
1055
+ async dispose() {
1056
+ const rpc = get(rpcId);
1057
+ await rpc.dispose();
1058
+ },
1059
+ // @ts-ignore
1060
+ invoke(method, ...params) {
1061
+ const rpc = get(rpcId);
1062
+ // @ts-ignore
1063
+ return rpc.invoke(method, ...params);
1064
+ },
1065
+ // @ts-ignore
1066
+ invokeAndTransfer(method, ...params) {
1067
+ const rpc = get(rpcId);
1068
+ // @ts-ignore
1069
+ return rpc.invokeAndTransfer(method, ...params);
1070
+ },
1071
+ registerMockRpc(commandMap) {
1072
+ const mockRpc = createMockRpc({
1073
+ commandMap
1074
+ });
1075
+ set$1(rpcId, mockRpc);
1076
+ // @ts-ignore
1077
+ mockRpc[Symbol.dispose] = () => {
1078
+ remove(rpcId);
1079
+ };
1080
+ // @ts-ignore
1081
+ return mockRpc;
1082
+ },
1083
+ set(rpc) {
1084
+ set$1(rpcId, rpc);
1085
+ }
1086
+ };
1087
+ };
1088
+
1089
+ const {
1090
+ invoke,
1091
+ set
1092
+ } = create(6007);
1093
+ const getMathBlockDom = async node => {
1094
+ return invoke('ChatMath.getMathBlockDom', node);
1095
+ };
1096
+ const getMathInlineDom = async node => {
1097
+ return invoke('ChatMath.getMathInlineDom', node);
1098
+ };
1099
+
1100
+ const RendererWorker = 1;
1101
+
1102
+ const {
1103
+ invokeAndTransfer} = create(RendererWorker);
1104
+ const sendMessagePortToChatMathWorker$1 = async (port, rpcId) => {
1105
+ const command = 'HandleMessagePort.handleMessagePort';
1106
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToChatMathWorker', port, command, rpcId);
1107
+ };
1108
+
1109
+ const parseMathInline = async children => {
1110
+ const nextChildren = [];
1111
+ for (const child of children) {
1112
+ if (child.type === 'math-inline') {
1113
+ const dom = await getMathInlineDom(child);
1114
+ nextChildren.push({
1115
+ dom,
1116
+ type: 'math-inline-dom'
1117
+ });
1118
+ continue;
1119
+ }
1120
+ if (child.type === 'bold') {
1121
+ nextChildren.push({
1122
+ ...child,
1123
+ children: await parseMathInline(child.children)
1124
+ });
1125
+ continue;
1126
+ }
1127
+ if (child.type === 'italic') {
1128
+ nextChildren.push({
1129
+ ...child,
1130
+ children: await parseMathInline(child.children)
1131
+ });
1132
+ continue;
1133
+ }
1134
+ if (child.type === 'strikethrough') {
1135
+ nextChildren.push({
1136
+ ...child,
1137
+ children: await parseMathInline(child.children)
1138
+ });
1139
+ continue;
1140
+ }
1141
+ nextChildren.push(child);
1142
+ }
1143
+ return nextChildren;
1144
+ };
1145
+ const parseMathListItem = async item => {
1146
+ const children = await parseMathInline(item.children);
1147
+ if (!item.nestedItems) {
1148
+ return {
1149
+ ...item,
1150
+ children
1151
+ };
1152
+ }
1153
+ const nestedItems = [];
1154
+ for (const nestedItem of item.nestedItems) {
1155
+ nestedItems.push(await parseMathListItem(nestedItem));
1156
+ }
1157
+ return {
1158
+ ...item,
1159
+ children,
1160
+ nestedItems
1161
+ };
1162
+ };
1163
+ const parseMathTableCell = async cell => {
1164
+ return {
1165
+ ...cell,
1166
+ children: await parseMathInline(cell.children)
1167
+ };
1168
+ };
1169
+ const parseMathNode = async node => {
1170
+ if (node.type === 'math-block') {
1171
+ const dom = await getMathBlockDom(node);
1172
+ return {
1173
+ dom,
1174
+ type: 'math-block-dom'
1175
+ };
1176
+ }
1177
+ if (node.type === 'text' || node.type === 'heading') {
1178
+ return {
1179
+ ...node,
1180
+ children: await parseMathInline(node.children)
1181
+ };
1182
+ }
1183
+ if (node.type === 'blockquote') {
1184
+ const children = [];
1185
+ for (const child of node.children) {
1186
+ children.push(await parseMathNode(child));
1187
+ }
1188
+ return {
1189
+ ...node,
1190
+ children
1191
+ };
1192
+ }
1193
+ if (node.type === 'ordered-list' || node.type === 'unordered-list') {
1194
+ const items = [];
1195
+ for (const item of node.items) {
1196
+ items.push(await parseMathListItem(item));
1197
+ }
1198
+ return {
1199
+ ...node,
1200
+ items
1201
+ };
1202
+ }
1203
+ if (node.type === 'table') {
1204
+ const headers = [];
1205
+ for (const header of node.headers) {
1206
+ headers.push(await parseMathTableCell(header));
1207
+ }
1208
+ const rows = [];
1209
+ for (const row of node.rows) {
1210
+ const cells = [];
1211
+ for (const cell of row.cells) {
1212
+ cells.push(await parseMathTableCell(cell));
1213
+ }
1214
+ rows.push({
1215
+ ...row,
1216
+ cells
1217
+ });
1218
+ }
1219
+ return {
1220
+ ...node,
1221
+ headers,
1222
+ rows
1223
+ };
1224
+ }
1225
+ return node;
1226
+ };
1227
+
1228
+ const TokenAttribute = 'TokenAttribute';
1229
+ const TokenComment = 'TokenComment';
1230
+ const TokenKeyword = 'TokenKeyword';
1231
+ const TokenNumber = 'TokenNumber';
1232
+ const TokenProperty = 'TokenProperty';
1233
+ const TokenString = 'TokenString';
1234
+ const TokenTag = 'TokenTag';
1235
+ const TokenValue = 'TokenValue';
1236
+
1237
+ const jsRules = [{
1238
+ className: TokenComment,
1239
+ regex: /\/\/[^\n]*/
1240
+ }, {
1241
+ className: TokenComment,
1242
+ regex: /\/\*[\s\S]*?\*\//
1243
+ }, {
1244
+ className: TokenString,
1245
+ regex: /"[^"\\]*(?:\\.[^"\\]*)*"/
1246
+ }, {
1247
+ className: TokenString,
1248
+ regex: /'[^'\\]*(?:\\.[^'\\]*)*'/
1249
+ }, {
1250
+ className: TokenString,
1251
+ regex: /`[^`\\]*(?:\\.[^`\\]*)*`/
1252
+ }, {
1253
+ className: TokenNumber,
1254
+ regex: /\b\d+\.?\d*\b/
1255
+ }, {
1256
+ className: TokenKeyword,
1257
+ regex: /\b(?:const|let|var|function|return|if|else|for|while|class|new|typeof|instanceof|import|export|from|default|async|await|try|catch|finally|throw|this|true|false|null|undefined)\b/
1258
+ }];
1259
+ const tsRules = [{
1260
+ className: TokenComment,
1261
+ regex: /\/\/[^\n]*/
1262
+ }, {
1263
+ className: TokenComment,
1264
+ regex: /\/\*[\s\S]*?\*\//
1265
+ }, {
1266
+ className: TokenString,
1267
+ regex: /"[^"\\]*(?:\\.[^"\\]*)*"/
1268
+ }, {
1269
+ className: TokenString,
1270
+ regex: /'[^'\\]*(?:\\.[^'\\]*)*'/
1271
+ }, {
1272
+ className: TokenString,
1273
+ regex: /`[^`\\]*(?:\\.[^`\\]*)*`/
1274
+ }, {
1275
+ className: TokenNumber,
1276
+ regex: /\b\d+\.?\d*\b/
1277
+ }, {
1278
+ className: TokenKeyword,
1279
+ regex: /\b(?:abstract|any|as|asserts|async|await|boolean|class|const|constructor|declare|default|enum|export|extends|false|finally|for|from|function|get|if|implements|import|in|infer|instanceof|interface|is|keyof|let|module|namespace|never|new|null|number|object|override|private|protected|public|readonly|return|satisfies|set|static|string|super|switch|symbol|this|throw|true|try|type|typeof|undefined|unknown|var|void|while)\b/
1280
+ }];
1281
+ const htmlRules = [{
1282
+ className: TokenComment,
1283
+ regex: /<!--[\s\S]*?-->/
1284
+ }, {
1285
+ className: TokenTag,
1286
+ regex: /<\/[a-zA-Z][a-zA-Z0-9-]*\s*>/
1287
+ }, {
1288
+ className: TokenTag,
1289
+ regex: /<[a-zA-Z][a-zA-Z0-9-]*/
1290
+ }, {
1291
+ className: TokenTag,
1292
+ regex: /\/?>/
1293
+ }, {
1294
+ className: TokenString,
1295
+ regex: /"[^"]*"/
1296
+ }, {
1297
+ className: TokenString,
1298
+ regex: /'[^']*'/
1299
+ }, {
1300
+ className: TokenAttribute,
1301
+ regex: /[a-zA-Z-]+(?=\s*=)/
1302
+ }];
1303
+ const cssRules = [{
1304
+ className: TokenComment,
1305
+ regex: /\/\*[\s\S]*?\*\//
1306
+ }, {
1307
+ className: TokenString,
1308
+ regex: /"[^"]*"/
1309
+ }, {
1310
+ className: TokenString,
1311
+ regex: /'[^']*'/
1312
+ }, {
1313
+ className: TokenValue,
1314
+ regex: /#[0-9a-fA-F]{3,8}/
1315
+ }, {
1316
+ className: TokenValue,
1317
+ regex: /\b\d+(?:\.\d+)?(?:px|em|rem|%|vh|vw|pt|s|ms|fr)?\b/
1318
+ }, {
1319
+ className: TokenProperty,
1320
+ regex: /[a-zA-Z-]+(?=\s*:)/
1321
+ }];
1322
+ const pythonRules = [{
1323
+ className: TokenComment,
1324
+ regex: /#[^\n]*/
1325
+ }, {
1326
+ className: TokenString,
1327
+ regex: /"[^"\\]*(?:\\.[^"\\]*)*"/
1328
+ }, {
1329
+ className: TokenString,
1330
+ regex: /'[^'\\]*(?:\\.[^'\\]*)*'/
1331
+ }, {
1332
+ className: TokenNumber,
1333
+ regex: /\b\d+\.?\d*\b/
1334
+ }, {
1335
+ className: TokenKeyword,
1336
+ regex: /\b(?:def|class|return|if|elif|else|for|while|in|import|from|as|with|try|except|finally|raise|lambda|yield|pass|break|continue|True|False|None|and|or|not|is)\b/
1337
+ }];
1338
+ const jsonRules = [{
1339
+ className: TokenProperty,
1340
+ regex: /"[^"\\]*(?:\\.[^"\\]*)*"(?=\s*:)/
1341
+ }, {
1342
+ className: TokenString,
1343
+ regex: /"[^"\\]*(?:\\.[^"\\]*)*"/
1344
+ }, {
1345
+ className: TokenNumber,
1346
+ regex: /-?\b\d+\.?\d*(?:[eE][+-]?\d+)?\b/
1347
+ }, {
1348
+ className: TokenKeyword,
1349
+ regex: /\b(?:true|false|null)\b/
1350
+ }];
1351
+ const tokenize = (code, rules) => {
1352
+ const tokens = [];
1353
+ let pos = 0;
1354
+ while (pos < code.length) {
1355
+ let matched = false;
1356
+ for (const rule of rules) {
1357
+ const match = rule.regex.exec(code.slice(pos));
1358
+ if (match && match.index === 0) {
1359
+ tokens.push({
1360
+ className: rule.className,
1361
+ text: match[0]
1362
+ });
1363
+ pos += match[0].length;
1364
+ matched = true;
1365
+ break;
1366
+ }
1367
+ }
1368
+ if (!matched) {
1369
+ const last = tokens.at(-1);
1370
+ if (last && last.className === '') {
1371
+ tokens.pop();
1372
+ tokens.push({
1373
+ className: '',
1374
+ text: last.text + code[pos]
1375
+ });
1376
+ } else {
1377
+ tokens.push({
1378
+ className: '',
1379
+ text: code[pos]
1380
+ });
1381
+ }
1382
+ pos++;
1383
+ }
1384
+ }
1385
+ return tokens;
1386
+ };
1387
+ const highlightCode = (code, language) => {
1388
+ if (!language) {
1389
+ return [{
1390
+ className: '',
1391
+ text: code
1392
+ }];
1393
+ }
1394
+ const normalized = language.toLowerCase();
1395
+ if (normalized === 'html') {
1396
+ return tokenize(code, htmlRules);
1397
+ }
1398
+ if (normalized === 'css') {
1399
+ return tokenize(code, cssRules);
1400
+ }
1401
+ if (normalized === 'js' || normalized === 'javascript') {
1402
+ return tokenize(code, jsRules);
1403
+ }
1404
+ if (normalized === 'ts' || normalized === 'typescript') {
1405
+ return tokenize(code, tsRules);
1406
+ }
1407
+ if (normalized === 'py' || normalized === 'python') {
1408
+ return tokenize(code, pythonRules);
1409
+ }
1410
+ if (normalized === 'json') {
1411
+ return tokenize(code, jsonRules);
1412
+ }
1413
+ return [{
1414
+ className: '',
1415
+ text: code
1416
+ }];
1417
+ };
1418
+
958
1419
  const windowsAbsolutePathRegex = /^[a-zA-Z]:[\\/]/;
959
1420
  const pathSeparatorRegex$1 = /[\\/]/;
960
1421
  const isPathTraversalAttempt = path => {
@@ -1675,8 +2136,6 @@ const getEmptyTextNode = () => {
1675
2136
  type: 'text'
1676
2137
  }];
1677
2138
  };
1678
-
1679
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
1680
2139
  const parseBlockTokens = tokens => {
1681
2140
  if (tokens.length === 0) {
1682
2141
  return getEmptyTextNode();
@@ -1686,6 +2145,16 @@ const parseBlockTokens = tokens => {
1686
2145
  let listItems = [];
1687
2146
  let listType = '';
1688
2147
  let orderedListPathStack = [];
2148
+ let canContinueOrderedListItemParagraph = false;
2149
+ const createListItem = (text, index) => {
2150
+ return {
2151
+ children: parseInlineNodes(text),
2152
+ ...(index === undefined ? {} : {
2153
+ index
2154
+ }),
2155
+ type: 'list-item'
2156
+ };
2157
+ };
1689
2158
  const getListItemAtPath = (items, path) => {
1690
2159
  let currentItems = items;
1691
2160
  let currentItem;
@@ -1715,6 +2184,29 @@ const parseBlockTokens = tokens => {
1715
2184
  };
1716
2185
  return [...items.slice(0, index), nextItem, ...items.slice(index + 1)];
1717
2186
  };
2187
+ const appendInlineChildrenAtPath = (items, path, children) => {
2188
+ if (path.length === 0) {
2189
+ return [...items];
2190
+ }
2191
+ const [index, ...rest] = path;
2192
+ const current = items[index];
2193
+ if (!current) {
2194
+ return [...items];
2195
+ }
2196
+ const lineBreakNode = {
2197
+ text: '\n',
2198
+ type: 'text'
2199
+ };
2200
+ const nextChildren = [...current.children, lineBreakNode, ...children];
2201
+ const nextItem = rest.length > 0 ? {
2202
+ ...current,
2203
+ nestedItems: appendInlineChildrenAtPath(current.nestedItems || [], rest, children)
2204
+ } : {
2205
+ ...current,
2206
+ children: nextChildren
2207
+ };
2208
+ return [...items.slice(0, index), nextItem, ...items.slice(index + 1)];
2209
+ };
1718
2210
  const flushParagraph = () => {
1719
2211
  if (paragraphLines.length === 0) {
1720
2212
  return;
@@ -1736,11 +2228,13 @@ const parseBlockTokens = tokens => {
1736
2228
  listItems = [];
1737
2229
  listType = '';
1738
2230
  orderedListPathStack = [];
2231
+ canContinueOrderedListItemParagraph = false;
1739
2232
  };
1740
2233
  for (let i = 0; i < tokens.length; i++) {
1741
2234
  const token = tokens[i];
1742
2235
  if (token.type === 'blank-line') {
1743
2236
  flushParagraph();
2237
+ canContinueOrderedListItemParagraph = false;
1744
2238
  continue;
1745
2239
  }
1746
2240
  if (token.type === 'code-block') {
@@ -1748,12 +2242,14 @@ const parseBlockTokens = tokens => {
1748
2242
  flushParagraph();
1749
2243
  if (token.language) {
1750
2244
  nodes.push({
2245
+ codeTokens: highlightCode(token.text, token.language),
1751
2246
  language: token.language,
1752
2247
  text: token.text,
1753
2248
  type: 'code-block'
1754
2249
  });
1755
2250
  } else {
1756
2251
  nodes.push({
2252
+ codeTokens: highlightCode(token.text, undefined),
1757
2253
  text: token.text,
1758
2254
  type: 'code-block'
1759
2255
  });
@@ -1830,17 +2326,15 @@ const parseBlockTokens = tokens => {
1830
2326
  if (parentEntry) {
1831
2327
  const parentItem = getListItemAtPath(listItems, parentEntry.path);
1832
2328
  if (parentItem) {
1833
- const nextItem = {
1834
- children: parseInlineNodes(token.text),
1835
- type: 'list-item'
1836
- };
1837
2329
  const nextIndex = parentItem.nestedItems?.length || 0;
2330
+ const nextItem = createListItem(token.text, nextIndex + 1);
1838
2331
  listItems = appendNestedItemAtPath(listItems, parentEntry.path, nextItem, 'ordered-list');
1839
2332
  const nextPath = [...parentEntry.path, nextIndex];
1840
2333
  orderedListPathStack = [...orderedListPathStack.filter(entry => entry.indentation < token.indentation), {
1841
2334
  indentation: token.indentation,
1842
2335
  path: nextPath
1843
2336
  }];
2337
+ canContinueOrderedListItemParagraph = true;
1844
2338
  continue;
1845
2339
  }
1846
2340
  }
@@ -1850,27 +2344,23 @@ const parseBlockTokens = tokens => {
1850
2344
  }
1851
2345
  flushParagraph();
1852
2346
  listType = 'ordered-list';
1853
- const nextItem = {
1854
- children: parseInlineNodes(token.text),
1855
- type: 'list-item'
1856
- };
2347
+ const nextIndex = listItems.length;
2348
+ const nextItem = createListItem(token.text, nextIndex + 1);
1857
2349
  listItems.push(nextItem);
1858
- const nextIndex = listItems.length - 1;
1859
2350
  orderedListPathStack = [...orderedListPathStack.filter(entry => entry.indentation < token.indentation), {
1860
2351
  indentation: token.indentation,
1861
2352
  path: [nextIndex]
1862
2353
  }];
2354
+ canContinueOrderedListItemParagraph = true;
1863
2355
  continue;
1864
2356
  }
1865
2357
  if (token.type === 'unordered-list-item-line') {
1866
2358
  if (listType === 'ordered-list' && listItems.length > 0 && token.indentation > 0 && orderedListPathStack.length > 0) {
1867
2359
  const parentEntry = orderedListPathStack.toReversed().find(entry => entry.indentation < token.indentation);
1868
2360
  if (parentEntry) {
1869
- const nextItem = {
1870
- children: parseInlineNodes(token.text),
1871
- type: 'list-item'
1872
- };
2361
+ const nextItem = createListItem(token.text);
1873
2362
  listItems = appendNestedItemAtPath(listItems, parentEntry.path, nextItem, 'unordered-list');
2363
+ canContinueOrderedListItemParagraph = false;
1874
2364
  continue;
1875
2365
  }
1876
2366
  }
@@ -1879,10 +2369,8 @@ const parseBlockTokens = tokens => {
1879
2369
  }
1880
2370
  flushParagraph();
1881
2371
  listType = 'unordered-list';
1882
- listItems.push({
1883
- children: parseInlineNodes(token.text),
1884
- type: 'list-item'
1885
- });
2372
+ listItems.push(createListItem(token.text));
2373
+ canContinueOrderedListItemParagraph = false;
1886
2374
  continue;
1887
2375
  }
1888
2376
  if (token.type === 'heading-line') {
@@ -1895,8 +2383,16 @@ const parseBlockTokens = tokens => {
1895
2383
  });
1896
2384
  continue;
1897
2385
  }
2386
+ if (token.type === 'paragraph-line' && listType === 'ordered-list' && listItems.length > 0 && canContinueOrderedListItemParagraph) {
2387
+ const currentPath = orderedListPathStack.at(-1)?.path;
2388
+ if (currentPath) {
2389
+ listItems = appendInlineChildrenAtPath(listItems, currentPath, parseInlineNodes(token.text));
2390
+ continue;
2391
+ }
2392
+ }
1898
2393
  flushList();
1899
2394
  paragraphLines.push(token.text);
2395
+ canContinueOrderedListItemParagraph = false;
1900
2396
  }
1901
2397
  flushList();
1902
2398
  flushParagraph();
@@ -1907,6 +2403,15 @@ const parseMessageContent = rawMessage => {
1907
2403
  return parseBlockTokens(scanBlockTokens(rawMessage));
1908
2404
  };
1909
2405
 
2406
+ const parseMessage = async rawMessage => {
2407
+ const parsedContent = parseMessageContent(rawMessage);
2408
+ const nextParsedContent = [];
2409
+ for (const node of parsedContent) {
2410
+ nextParsedContent.push(await parseMathNode(node));
2411
+ }
2412
+ return nextParsedContent;
2413
+ };
2414
+
1910
2415
  const parseMessageContents = rawMessages => {
1911
2416
  return rawMessages.map(parseMessageContent);
1912
2417
  };
@@ -1914,16 +2419,29 @@ const parseMessageContents = rawMessages => {
1914
2419
  const commandMap = {
1915
2420
  'ChatMessageParsing.parseMessageContent': parseMessageContent,
1916
2421
  'ChatMessageParsing.parseMessageContents': parseMessageContents,
2422
+ 'ChatParser.parseMessage': parseMessage,
1917
2423
  'ChatParser.parseMessageContent': parseMessageContent,
1918
2424
  'ChatParser.parseMessageContents': parseMessageContents,
1919
2425
  'HandleMessagePort.handleMessagePort': handleMessagePort,
1920
- initialize: (_, port) => handleMessagePort(port)
2426
+ initialize: initialize
2427
+ };
2428
+
2429
+ const sendMessagePortToChatMathWorker = async port => {
2430
+ await sendMessagePortToChatMathWorker$1(port, 0);
2431
+ };
2432
+ const initializeChatMathWorker = async () => {
2433
+ const rpc = await create$2({
2434
+ commandMap: {},
2435
+ send: sendMessagePortToChatMathWorker
2436
+ });
2437
+ set(rpc);
1921
2438
  };
1922
2439
 
1923
2440
  const listen = async () => {
1924
- await create({
2441
+ await create$1({
1925
2442
  commandMap: commandMap
1926
2443
  });
2444
+ await initializeChatMathWorker();
1927
2445
  };
1928
2446
 
1929
2447
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/chat-message-parsing-worker",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "Chat Message Parsing Worker",
5
5
  "repository": {
6
6
  "type": "git",