@depup/markdown-it 15.0.1-depup.8 → 15.0.2-depup.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.
@@ -1,4 +1,4 @@
1
- /*! markdown-it 15.0.1 https://github.com/markdown-it/markdown-it @license MIT */
1
+ /*! markdown-it 15.0.2 https://github.com/markdown-it/markdown-it @license MIT */
2
2
  import * as mdurl from "mdurl";
3
3
  import * as ucmicro from "uc.micro";
4
4
  import { decodeHTMLStrict } from "entities";
@@ -1182,6 +1182,14 @@ function replace(state) {
1182
1182
  var QUOTE_TEST_RE = /['"]/;
1183
1183
  var QUOTE_RE = /['"]/g;
1184
1184
  var APOSTROPHE = "’";
1185
+ var MAX_OPENERS = 1e3;
1186
+ function truncateStack(stack, heads, length) {
1187
+ while (stack.length > length) {
1188
+ const item = stack.pop();
1189
+ if (item.isSingleQuote) heads.single = item.prevSameQuoteIdx;
1190
+ else heads.double = item.prevSameQuoteIdx;
1191
+ }
1192
+ }
1185
1193
  function addReplacement(replacements, tokenIdx, pos, ch) {
1186
1194
  if (!replacements[tokenIdx]) replacements[tokenIdx] = [];
1187
1195
  replacements[tokenIdx].push({
@@ -1203,12 +1211,16 @@ function applyReplacements(str, replacements) {
1203
1211
  function process_inlines(tokens, state) {
1204
1212
  let j;
1205
1213
  const stack = [];
1214
+ const heads = {
1215
+ single: -1,
1216
+ double: -1
1217
+ };
1206
1218
  const replacements = {};
1207
1219
  for (let i = 0; i < tokens.length; i++) {
1208
1220
  const token = tokens[i];
1209
1221
  const thisLevel = tokens[i].level;
1210
1222
  for (j = stack.length - 1; j >= 0; j--) if (stack[j].level <= thisLevel) break;
1211
- stack.length = j + 1;
1223
+ truncateStack(stack, heads, j + 1);
1212
1224
  if (token.type !== "text") continue;
1213
1225
  const text = token.content;
1214
1226
  let pos = 0;
@@ -1260,11 +1272,10 @@ function process_inlines(tokens, state) {
1260
1272
  if (isSingle) addReplacement(replacements, i, t.index, APOSTROPHE);
1261
1273
  continue;
1262
1274
  }
1263
- if (canClose) for (j = stack.length - 1; j >= 0; j--) {
1264
- let item = stack[j];
1265
- if (stack[j].level < thisLevel) break;
1266
- if (item.single === isSingle && stack[j].level === thisLevel) {
1267
- item = stack[j];
1275
+ if (canClose) {
1276
+ j = isSingle ? heads.single : heads.double;
1277
+ if (j >= 0 && stack[j].level === thisLevel) {
1278
+ const item = stack[j];
1268
1279
  let openQuote;
1269
1280
  let closeQuote;
1270
1281
  if (isSingle) {
@@ -1275,18 +1286,23 @@ function process_inlines(tokens, state) {
1275
1286
  closeQuote = state.md.options.quotes[1];
1276
1287
  }
1277
1288
  addReplacement(replacements, i, t.index, closeQuote);
1278
- addReplacement(replacements, item.token, item.pos, openQuote);
1279
- stack.length = j;
1289
+ addReplacement(replacements, item.tokenIdx, item.contentPos, openQuote);
1290
+ truncateStack(stack, heads, j);
1280
1291
  continue OUTER;
1281
1292
  }
1282
1293
  }
1283
- if (canOpen) stack.push({
1284
- token: i,
1285
- pos: t.index,
1286
- single: isSingle,
1287
- level: thisLevel
1288
- });
1289
- else if (canClose && isSingle) addReplacement(replacements, i, t.index, APOSTROPHE);
1294
+ if (canOpen) {
1295
+ if (stack.length >= MAX_OPENERS) return;
1296
+ stack.push({
1297
+ tokenIdx: i,
1298
+ contentPos: t.index,
1299
+ isSingleQuote: isSingle,
1300
+ level: thisLevel,
1301
+ prevSameQuoteIdx: isSingle ? heads.single : heads.double
1302
+ });
1303
+ if (isSingle) heads.single = stack.length - 1;
1304
+ else heads.double = stack.length - 1;
1305
+ } else if (canClose && isSingle) addReplacement(replacements, i, t.index, APOSTROPHE);
1290
1306
  }
1291
1307
  }
1292
1308
  Object.keys(replacements).forEach(function(tokenIdx) {