@mtcute/markdown-parser 0.22.3 → 0.24.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.
- package/index.cjs +26 -0
- package/index.js +26 -0
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -109,6 +109,8 @@ function parse(strings, ...sub) {
|
|
|
109
109
|
let insideCode = false;
|
|
110
110
|
let insidePre = false;
|
|
111
111
|
let insideLink = false;
|
|
112
|
+
let currentBlockquoteStart = null;
|
|
113
|
+
let prevBlockquote = null;
|
|
112
114
|
let insideLinkUrl = false;
|
|
113
115
|
let pendingLinkUrl = "";
|
|
114
116
|
function feed(text) {
|
|
@@ -299,6 +301,29 @@ function parse(strings, ...sub) {
|
|
|
299
301
|
} else {
|
|
300
302
|
pos = len;
|
|
301
303
|
}
|
|
304
|
+
if (currentBlockquoteStart != null) {
|
|
305
|
+
const prevEnd = prevBlockquote ? prevBlockquote.offset + prevBlockquote.length : Number.NaN;
|
|
306
|
+
if (currentBlockquoteStart - 1 === prevEnd) {
|
|
307
|
+
prevBlockquote.length += result.length - currentBlockquoteStart;
|
|
308
|
+
} else {
|
|
309
|
+
if (prevBlockquote) entities.push(prevBlockquote);
|
|
310
|
+
prevBlockquote = {
|
|
311
|
+
_: "messageEntityBlockquote",
|
|
312
|
+
offset: currentBlockquoteStart,
|
|
313
|
+
length: result.length - currentBlockquoteStart - 1
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
currentBlockquoteStart = null;
|
|
317
|
+
}
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (c === ">" && (result.length === 0 || result[result.length - 1] === "\n")) {
|
|
321
|
+
currentBlockquoteStart = result.length;
|
|
322
|
+
pos += 1;
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (c === " " && currentBlockquoteStart === result.length) {
|
|
326
|
+
pos += 1;
|
|
302
327
|
continue;
|
|
303
328
|
}
|
|
304
329
|
result += c;
|
|
@@ -336,6 +361,7 @@ function parse(strings, ...sub) {
|
|
|
336
361
|
}
|
|
337
362
|
});
|
|
338
363
|
feed(strings[strings.length - 1]);
|
|
364
|
+
if (prevBlockquote) entities.push(prevBlockquote);
|
|
339
365
|
function adjustOffsets(from, by) {
|
|
340
366
|
for (const ent of entities) {
|
|
341
367
|
if (ent.offset >= from) ent.offset += by;
|
package/index.js
CHANGED
|
@@ -102,6 +102,8 @@ function parse(strings, ...sub) {
|
|
|
102
102
|
let insideCode = false;
|
|
103
103
|
let insidePre = false;
|
|
104
104
|
let insideLink = false;
|
|
105
|
+
let currentBlockquoteStart = null;
|
|
106
|
+
let prevBlockquote = null;
|
|
105
107
|
let insideLinkUrl = false;
|
|
106
108
|
let pendingLinkUrl = "";
|
|
107
109
|
function feed(text) {
|
|
@@ -292,6 +294,29 @@ function parse(strings, ...sub) {
|
|
|
292
294
|
} else {
|
|
293
295
|
pos = len;
|
|
294
296
|
}
|
|
297
|
+
if (currentBlockquoteStart != null) {
|
|
298
|
+
const prevEnd = prevBlockquote ? prevBlockquote.offset + prevBlockquote.length : Number.NaN;
|
|
299
|
+
if (currentBlockquoteStart - 1 === prevEnd) {
|
|
300
|
+
prevBlockquote.length += result.length - currentBlockquoteStart;
|
|
301
|
+
} else {
|
|
302
|
+
if (prevBlockquote) entities.push(prevBlockquote);
|
|
303
|
+
prevBlockquote = {
|
|
304
|
+
_: "messageEntityBlockquote",
|
|
305
|
+
offset: currentBlockquoteStart,
|
|
306
|
+
length: result.length - currentBlockquoteStart - 1
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
currentBlockquoteStart = null;
|
|
310
|
+
}
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (c === ">" && (result.length === 0 || result[result.length - 1] === "\n")) {
|
|
314
|
+
currentBlockquoteStart = result.length;
|
|
315
|
+
pos += 1;
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
if (c === " " && currentBlockquoteStart === result.length) {
|
|
319
|
+
pos += 1;
|
|
295
320
|
continue;
|
|
296
321
|
}
|
|
297
322
|
result += c;
|
|
@@ -329,6 +354,7 @@ function parse(strings, ...sub) {
|
|
|
329
354
|
}
|
|
330
355
|
});
|
|
331
356
|
feed(strings[strings.length - 1]);
|
|
357
|
+
if (prevBlockquote) entities.push(prevBlockquote);
|
|
332
358
|
function adjustOffsets(from, by) {
|
|
333
359
|
for (const ent of entities) {
|
|
334
360
|
if (ent.offset >= from) ent.offset += by;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mtcute/markdown-parser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.24.0",
|
|
5
5
|
"description": "Markdown entities parser for mtcute",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@mtcute/core": "^0.
|
|
8
|
+
"@mtcute/core": "^0.24.0",
|
|
9
9
|
"long": "5.2.3"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|