mathpix-markdown-it 1.0.98 → 1.2.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.
Files changed (101) hide show
  1. package/.idea/workspace.xml +603 -402
  2. package/es5/bundle.js +1 -1
  3. package/es5/index.js +1 -1
  4. package/lib/components/mathpix-markdown/index.js +4 -2
  5. package/lib/components/mathpix-markdown/index.js.map +1 -1
  6. package/lib/markdown/common/consts.d.ts +2 -0
  7. package/lib/markdown/common/consts.js +3 -1
  8. package/lib/markdown/common/consts.js.map +1 -1
  9. package/lib/markdown/common.d.ts +3 -0
  10. package/lib/markdown/common.js +2 -1
  11. package/lib/markdown/common.js.map +1 -1
  12. package/lib/markdown/highlight/common.d.ts +6 -0
  13. package/lib/markdown/highlight/common.js +172 -0
  14. package/lib/markdown/highlight/common.js.map +1 -0
  15. package/lib/markdown/highlight/highlight-math-token.d.ts +4 -0
  16. package/lib/markdown/highlight/highlight-math-token.js +261 -0
  17. package/lib/markdown/highlight/highlight-math-token.js.map +1 -0
  18. package/lib/markdown/highlight/render-rule-highlights.d.ts +5 -0
  19. package/lib/markdown/highlight/render-rule-highlights.js +152 -0
  20. package/lib/markdown/highlight/render-rule-highlights.js.map +1 -0
  21. package/lib/markdown/index.js +8 -2
  22. package/lib/markdown/index.js.map +1 -1
  23. package/lib/markdown/mathpix-markdown-plugins.js +112 -2
  24. package/lib/markdown/mathpix-markdown-plugins.js.map +1 -1
  25. package/lib/markdown/md-block-rule/begin-table.js +52 -1
  26. package/lib/markdown/md-block-rule/begin-table.js.map +1 -1
  27. package/lib/markdown/md-block-rule/begin-tabular/index.d.ts +1 -1
  28. package/lib/markdown/md-block-rule/begin-tabular/index.js +4 -2
  29. package/lib/markdown/md-block-rule/begin-tabular/index.js.map +1 -1
  30. package/lib/markdown/md-block-rule/helper.d.ts +1 -1
  31. package/lib/markdown/md-block-rule/helper.js +8 -1
  32. package/lib/markdown/md-block-rule/helper.js.map +1 -1
  33. package/lib/markdown/md-block-rule/lists/index.js +3 -0
  34. package/lib/markdown/md-block-rule/lists/index.js.map +1 -1
  35. package/lib/markdown/md-core-rules/set-positions.d.ts +1 -0
  36. package/lib/markdown/md-core-rules/set-positions.js +281 -0
  37. package/lib/markdown/md-core-rules/set-positions.js.map +1 -0
  38. package/lib/markdown/md-inline-rule/image.js +4 -0
  39. package/lib/markdown/md-inline-rule/image.js.map +1 -1
  40. package/lib/markdown/md-inline-rule/includegraphics.js +15 -2
  41. package/lib/markdown/md-inline-rule/includegraphics.js.map +1 -1
  42. package/lib/markdown/md-inline-rule/lists.js +6 -0
  43. package/lib/markdown/md-inline-rule/lists.js.map +1 -1
  44. package/lib/markdown/md-inline-rule/new-line-to-space.d.ts +2 -0
  45. package/lib/markdown/md-inline-rule/new-line-to-space.js +46 -0
  46. package/lib/markdown/md-inline-rule/new-line-to-space.js.map +1 -0
  47. package/lib/markdown/md-inline-rule/setcounter-section.js +6 -0
  48. package/lib/markdown/md-inline-rule/setcounter-section.js.map +1 -1
  49. package/lib/markdown/md-inline-rule/text-collapse.d.ts +1 -0
  50. package/lib/markdown/md-inline-rule/text-collapse.js +43 -0
  51. package/lib/markdown/md-inline-rule/text-collapse.js.map +1 -0
  52. package/lib/markdown/md-inline-rule/utils.d.ts +1 -0
  53. package/lib/markdown/md-inline-rule/utils.js +2 -1
  54. package/lib/markdown/md-inline-rule/utils.js.map +1 -1
  55. package/lib/markdown/md-renderer-rules/index.js +3 -1
  56. package/lib/markdown/md-renderer-rules/index.js.map +1 -1
  57. package/lib/markdown/md-renderer-rules/render-lists.js +7 -0
  58. package/lib/markdown/md-renderer-rules/render-lists.js.map +1 -1
  59. package/lib/markdown/md-renderer-rules/render-tabular.d.ts +1 -1
  60. package/lib/markdown/md-renderer-rules/render-tabular.js +29 -3
  61. package/lib/markdown/md-renderer-rules/render-tabular.js.map +1 -1
  62. package/lib/markdown/md-theorem/block-rule.js +80 -14
  63. package/lib/markdown/md-theorem/block-rule.js.map +1 -1
  64. package/lib/markdown/md-theorem/index.js +11 -1
  65. package/lib/markdown/md-theorem/index.js.map +1 -1
  66. package/lib/markdown/md-theorem/inline-rule.js +24 -0
  67. package/lib/markdown/md-theorem/inline-rule.js.map +1 -1
  68. package/lib/markdown/mdPluginAnchor.js +4 -2
  69. package/lib/markdown/mdPluginAnchor.js.map +1 -1
  70. package/lib/markdown/mdPluginConfigured.d.ts +1 -0
  71. package/lib/markdown/mdPluginConfigured.js +3 -1
  72. package/lib/markdown/mdPluginConfigured.js.map +1 -1
  73. package/lib/markdown/mdPluginRaw.js +50 -3
  74. package/lib/markdown/mdPluginRaw.js.map +1 -1
  75. package/lib/markdown/mdPluginText.js +224 -27
  76. package/lib/markdown/mdPluginText.js.map +1 -1
  77. package/lib/markdown/mdSetPositionsAndHighlight.d.ts +2 -0
  78. package/lib/markdown/mdSetPositionsAndHighlight.js +22 -0
  79. package/lib/markdown/mdSetPositionsAndHighlight.js.map +1 -0
  80. package/lib/markdown/utils.d.ts +3 -0
  81. package/lib/markdown/utils.js +292 -1
  82. package/lib/markdown/utils.js.map +1 -1
  83. package/lib/mathjax/index.d.ts +31 -2
  84. package/lib/mathjax/index.js +21 -12
  85. package/lib/mathjax/index.js.map +1 -1
  86. package/lib/mathjax/my-BaseMappings.js +7 -1
  87. package/lib/mathjax/my-BaseMappings.js.map +1 -1
  88. package/lib/mathpix-markdown-model/index.d.ts +12 -0
  89. package/lib/mathpix-markdown-model/index.js +4 -2
  90. package/lib/mathpix-markdown-model/index.js.map +1 -1
  91. package/lib/styles/index.js +1 -1
  92. package/lib/styles/index.js.map +1 -1
  93. package/lib/styles/styles-code.d.ts +1 -1
  94. package/lib/styles/styles-code.js +1 -1
  95. package/lib/styles/styles-code.js.map +1 -1
  96. package/lib/styles/styles-fonts.d.ts +1 -1
  97. package/lib/styles/styles-fonts.js +1 -1
  98. package/lib/styles/styles-fonts.js.map +1 -1
  99. package/lib/styles/styles-tabular.js +1 -1
  100. package/lib/styles/styles-tabular.js.map +1 -1
  101. package/package.json +1 -1
@@ -8,6 +8,9 @@ var consts_1 = require("./common/consts");
8
8
  var common_1 = require("./common");
9
9
  var utils_1 = require("./utils");
10
10
  var labels_1 = require("./common/labels");
11
+ var text_collapse_1 = require("./md-inline-rule/text-collapse");
12
+ var new_line_to_space_1 = require("./md-inline-rule/new-line-to-space");
13
+ var common_2 = require("./highlight/common");
11
14
  exports.sectionCount = 0;
12
15
  exports.subCount = 0;
13
16
  exports.subSubCount = 0;
@@ -212,7 +215,10 @@ exports.headingSection = function (state, startLine, endLine, silent) {
212
215
  var token, lineText, pos = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine];
213
216
  var nextLine = startLine + 1;
214
217
  var startPos = 0, type, className = '', is_numerable = false, beginMarker = "{", level = 1;
215
- lineText = state.src.slice(pos, max).trim();
218
+ lineText = state.src.slice(pos, max);
219
+ /** line begin offsets */
220
+ var bMarks = lineText.length - lineText.trimLeft().length;
221
+ lineText = lineText.trimLeft();
216
222
  if (state.src.charCodeAt(pos) !== 0x5c /* \ */) {
217
223
  return false;
218
224
  }
@@ -222,6 +228,10 @@ exports.headingSection = function (state, startLine, endLine, silent) {
222
228
  if (!match) {
223
229
  return false;
224
230
  }
231
+ /** For validation mode we can terminate immediately */
232
+ if (silent) {
233
+ return true;
234
+ }
225
235
  var attrStyle = '';
226
236
  var isUnNumbered = false;
227
237
  startPos += match[0].length;
@@ -276,13 +286,18 @@ exports.headingSection = function (state, startLine, endLine, silent) {
276
286
  if (lineText[startPos] !== beginMarker) {
277
287
  return false;
278
288
  }
279
- var _b = common_1.findEndMarker(lineText, startPos), _c = _b.res, res = _c === void 0 ? false : _c, _d = _b.content, content = _d === void 0 ? '' : _d, _e = _b.nextPos, nextPos = _e === void 0 ? 0 : _e;
289
+ var _b = common_1.findEndMarker(lineText, startPos), _c = _b.res, res = _c === void 0 ? false : _c, _d = _b.content, content = _d === void 0 ? '' : _d, _e = _b.nextPos, nextPos = _e === void 0 ? 0 : _e, _f = _b.endPos, endPos = _f === void 0 ? 0 : _f;
280
290
  var resString = content;
281
- resString = resString.split('\\\\').join('\n');
291
+ // resString = resString.split('\\\\').join('\n');
282
292
  var hasEndMarker = false;
283
293
  var last = nextLine;
294
+ var eMarks = 0; //line end offsets
295
+ var bMarksContent = startPos;
284
296
  var inlineStr = '';
285
297
  if (!res) {
298
+ // resString += resString ? ' ' : '';
299
+ bMarksContent += (content === null || content === void 0 ? void 0 : content.length) ? 0 : 1;
300
+ bMarksContent += state.tShift[nextLine];
286
301
  for (; nextLine <= endLine; nextLine++) {
287
302
  if (lineText === '') {
288
303
  break;
@@ -290,10 +305,11 @@ exports.headingSection = function (state, startLine, endLine, silent) {
290
305
  pos = state.bMarks[nextLine] + state.tShift[nextLine];
291
306
  max = state.eMarks[nextLine];
292
307
  lineText = state.src.slice(pos, max);
293
- var _f = common_1.findEndMarker(lineText, -1, "{", "}", true), _g = _f.res, res_2 = _g === void 0 ? false : _g, _h = _f.content, content_2 = _h === void 0 ? '' : _h, _j = _f.nextPos, nextPos_2 = _j === void 0 ? 0 : _j;
308
+ var _g = common_1.findEndMarker(lineText, -1, "{", "}", true), _h = _g.res, res_2 = _h === void 0 ? false : _h, _j = _g.content, content_2 = _j === void 0 ? '' : _j, _k = _g.nextPos, nextPos_2 = _k === void 0 ? 0 : _k, _l = _g.endPos, endPos_1 = _l === void 0 ? 0 : _l;
294
309
  if (res_2) {
310
+ eMarks = endPos_1 + 1;
295
311
  resString += resString ? ' ' : '';
296
- content_2 = content_2.split('\\\\').join('\n');
312
+ // content = content.split('\\\\').join('\n');
297
313
  resString += content_2;
298
314
  hasEndMarker = true;
299
315
  if (nextPos_2 && nextPos_2 < lineText.length) {
@@ -302,12 +318,13 @@ exports.headingSection = function (state, startLine, endLine, silent) {
302
318
  break;
303
319
  }
304
320
  resString += resString ? ' ' : '';
305
- lineText = lineText.split('\\\\').join('\n');
321
+ // lineText = lineText.split('\\\\').join('\n');
306
322
  resString += lineText;
307
323
  }
308
324
  last = nextLine + 1;
309
325
  }
310
326
  else {
327
+ eMarks = endPos;
311
328
  hasEndMarker = true;
312
329
  last = nextLine;
313
330
  if (nextPos && nextPos < lineText.length) {
@@ -317,10 +334,6 @@ exports.headingSection = function (state, startLine, endLine, silent) {
317
334
  if (!hasEndMarker) {
318
335
  return false;
319
336
  }
320
- /** For validation mode we can terminate immediately */
321
- if (silent) {
322
- return true;
323
- }
324
337
  state.line = last;
325
338
  token = state.push('heading_open', 'h' + String(level), 1);
326
339
  if (state.md.options.forLatex) {
@@ -339,12 +352,20 @@ exports.headingSection = function (state, startLine, endLine, silent) {
339
352
  }
340
353
  token = state.push('inline', '', 0);
341
354
  token.content = resString;
355
+ token.content_id = resString.split('\\\\').join('\n');
342
356
  token.type = type;
343
357
  token.is_numerable = is_numerable;
344
358
  token.isUnNumbered = isUnNumbered;
345
359
  token.map = [startLine, state.line];
360
+ token.bMarks = bMarks;
361
+ token.eMarks = eMarks ? eMarks : token.bMarks + resString.length;
362
+ token.bMarksContent = bMarks + bMarksContent + beginMarker.length;
363
+ token.eMarksContent = token.eMarks;
364
+ token.eMarks += 1;
346
365
  var children = [];
347
- state.md.inline.parse(token.content.trim(), state.md, state.env, children);
366
+ state.env.doubleSlashToSoftBreak = true; /** for // - should be new line */
367
+ state.md.inline.parse(token.content, state.md, state.env, children);
368
+ state.env.doubleSlashToSoftBreak = false;
348
369
  token.children = children;
349
370
  if (type === "section" && !isUnNumbered) {
350
371
  exports.sectionCount = exports.sectionCount ? exports.sectionCount + 1 : 1;
@@ -408,7 +429,9 @@ exports.headingSection = function (state, startLine, endLine, silent) {
408
429
  }
409
430
  return true;
410
431
  };
432
+ /** TODO: Need to change this rule to separate rendering of the entire block abstract */
411
433
  var abstractBlock = function (state, startLine, endLine, silent) {
434
+ var _a;
412
435
  var isBlockOpened = false;
413
436
  var token;
414
437
  var content;
@@ -421,6 +444,7 @@ var abstractBlock = function (state, startLine, endLine, silent) {
421
444
  var terminatorRules = state.md.block.ruler.getRules('paragraph');
422
445
  var lineText = state.src.slice(pos, max);
423
446
  var isCloseTagExist = false;
447
+ var arrContent = [];
424
448
  if (!openTag.test(lineText)) {
425
449
  return false;
426
450
  }
@@ -436,6 +460,14 @@ var abstractBlock = function (state, startLine, endLine, silent) {
436
460
  if (match) {
437
461
  inline = lineText.slice(match.index + match[0].length);
438
462
  }
463
+ if (inline && inline.trim()) {
464
+ arrContent.push({
465
+ line: startLine,
466
+ bMarks: state.tShift[startLine] + match.index + match[0].length,
467
+ eMarks: lineText.length,
468
+ content: inline
469
+ });
470
+ }
439
471
  for (; nextLine < endLine; nextLine++) {
440
472
  if (closeTag.test(lineText)) {
441
473
  lineText += '\\n';
@@ -449,6 +481,14 @@ var abstractBlock = function (state, startLine, endLine, silent) {
449
481
  max = state.eMarks[nextLine];
450
482
  lineText = state.src.slice(pos, max);
451
483
  lastLine = state.src.slice(pos, max);
484
+ if (!closeTag.test(lineText)) {
485
+ arrContent.push({
486
+ line: nextLine,
487
+ bMarks: 0,
488
+ eMarks: state.tShift[nextLine] + lineText.length,
489
+ content: lineText
490
+ });
491
+ }
452
492
  if (abs) {
453
493
  if (closeTag.test(lineText)) {
454
494
  isBlockOpened = false;
@@ -501,6 +541,19 @@ var abstractBlock = function (state, startLine, endLine, silent) {
501
541
  if (matchEnd) {
502
542
  strBeforeEnd = lastLine.slice(0, matchEnd.index);
503
543
  strAfterEnd = lastLine.slice(matchEnd.index + matchEnd[0].length);
544
+ if (strBeforeEnd) {
545
+ arrContent.push({
546
+ line: nextLine,
547
+ eMarks: matchEnd.index + 1,
548
+ content: strBeforeEnd
549
+ });
550
+ }
551
+ else {
552
+ if (arrContent === null || arrContent === void 0 ? void 0 : arrContent.length) {
553
+ arrContent[arrContent.length - 1].endLine = arrContent[arrContent.length - 1].line + 1;
554
+ arrContent[arrContent.length - 1].eMarks += 1;
555
+ }
556
+ }
504
557
  }
505
558
  }
506
559
  content = resString;
@@ -510,6 +563,30 @@ var abstractBlock = function (state, startLine, endLine, silent) {
510
563
  if (strBeforeEnd && strBeforeEnd.trim()) {
511
564
  content += strBeforeEnd;
512
565
  }
566
+ var contentItems = [];
567
+ var start = null;
568
+ for (var i = 0; i < arrContent.length; i++) {
569
+ if (!start) {
570
+ start = arrContent[i];
571
+ continue;
572
+ }
573
+ if ((_a = arrContent[i].content) === null || _a === void 0 ? void 0 : _a.trim()) {
574
+ start.endLine = arrContent[i].hasOwnProperty('endLine') ? arrContent[i].endLine : arrContent[i].line;
575
+ start.content += start.content ? ' ' : '';
576
+ start.content += arrContent[i].content;
577
+ start.eMarks = arrContent[i].eMarks ? arrContent[i].eMarks : 0;
578
+ }
579
+ else {
580
+ start.endLine = arrContent[i].line;
581
+ start.eMarks = arrContent[i].eMarks ? arrContent[i].eMarks : 0;
582
+ contentItems.push(start);
583
+ start = null;
584
+ }
585
+ }
586
+ ;
587
+ if (start) {
588
+ contentItems.push(start);
589
+ }
513
590
  var contentList = content.split('\n');
514
591
  var tokenContent = contentList.filter(function (item) {
515
592
  return item.trim().length > 0;
@@ -518,11 +595,13 @@ var abstractBlock = function (state, startLine, endLine, silent) {
518
595
  token.map = [startLine, nextLine];
519
596
  token.attrSet('class', 'abstract');
520
597
  token.attrSet('style', 'width: 80%; margin: 0 auto; margin-bottom: 1em; font-size: .9em;');
598
+ token.mmd_type = 'abstract';
521
599
  token = state.push('heading_open', 'h4', 1);
522
600
  token.markup = '########'.slice(0, 4);
523
601
  token.attrSet('id', 'abstract_head');
524
602
  token.attrSet('class', 'abstract_head');
525
603
  token.attrSet('style', 'text-align: center;');
604
+ token.mmd_type = 'abstract_title';
526
605
  token = state.push('text', '', 0);
527
606
  token.content = 'Abstract';
528
607
  token.children = [];
@@ -532,8 +611,19 @@ var abstractBlock = function (state, startLine, endLine, silent) {
532
611
  token.attrSet('style', 'text-indent: 1em;');
533
612
  token = state.push('inline', '', 0);
534
613
  token.content = tokenContent[i].trim();
535
- token.map = [startLine, state.line];
614
+ if (contentItems[i]) {
615
+ token.map = [contentItems[i].line,
616
+ contentItems[i].line
617
+ ? contentItems[i].endLine
618
+ : contentItems[i].line];
619
+ token.bMarks = contentItems[i].bMarks ? contentItems[i].bMarks : 0;
620
+ token.eMarks = contentItems[i].eMarks ? contentItems[i].eMarks : 0;
621
+ }
622
+ else {
623
+ token.map = [startLine, state.line];
624
+ }
536
625
  token.children = [];
626
+ token.mmd_type = 'abstract_content';
537
627
  token = state.push('paragraph_close', 'p', -1);
538
628
  }
539
629
  token = state.push('paragraph_close', 'div', -1);
@@ -574,6 +664,9 @@ var pageBreaksBlock = function (state, startLine, endLine, silent) {
574
664
  }
575
665
  token = state.push("pagebreak", "", 0);
576
666
  token.content = '';
667
+ token.map = [startLine, nextLine];
668
+ token.bMarks = state.tShift[startLine];
669
+ token.eMarks = strAfterEnd ? startPos : 0;
577
670
  if (state.md.options.forLatex) {
578
671
  token.latex = '\\' + match[0];
579
672
  if (!strAfterEnd || !strAfterEnd.trim()) {
@@ -590,6 +683,8 @@ var pageBreaksBlock = function (state, startLine, endLine, silent) {
590
683
  token = state.push('inline', '', 0);
591
684
  token.content = strAfterEnd;
592
685
  token.children = [];
686
+ token.bMarks = startPos;
687
+ token.map = [startLine, nextLine];
593
688
  }
594
689
  if (state.md.options.showPageBreaks || (strAfterEnd === null || strAfterEnd === void 0 ? void 0 : strAfterEnd.trim())) {
595
690
  state.push('paragraph_close', 'div', -1);
@@ -598,7 +693,7 @@ var pageBreaksBlock = function (state, startLine, endLine, silent) {
598
693
  return true;
599
694
  };
600
695
  var textAuthor = function (state) {
601
- var _a;
696
+ var _a, _b;
602
697
  var startPos = state.pos;
603
698
  if (state.src.charCodeAt(startPos) !== 0x5c /* \ */) {
604
699
  return false;
@@ -610,7 +705,7 @@ var textAuthor = function (state) {
610
705
  return false;
611
706
  }
612
707
  startPos += match[0].length;
613
- var _b = common_1.findEndMarker(state.src, startPos), _c = _b.res, res = _c === void 0 ? false : _c, _d = _b.content, content = _d === void 0 ? '' : _d, _e = _b.nextPos, nextPos = _e === void 0 ? 0 : _e;
708
+ var _c = common_1.findEndMarker(state.src, startPos), _d = _c.res, res = _d === void 0 ? false : _d, _e = _c.content, content = _e === void 0 ? '' : _e, _f = _c.nextPos, nextPos = _f === void 0 ? 0 : _f;
614
709
  if (!res) {
615
710
  return false;
616
711
  }
@@ -622,7 +717,14 @@ var textAuthor = function (state) {
622
717
  }
623
718
  token.content = content;
624
719
  token.children = [];
720
+ token.inlinePos = {
721
+ start: state.pos,
722
+ end: nextPos,
723
+ start_content: startPos + 1,
724
+ end_content: nextPos - 1,
725
+ };
625
726
  var columns = content.split('\\and');
727
+ var pos = 0;
626
728
  for (var i = 0; i < columns.length; i++) {
627
729
  var column = columns[i]
628
730
  ? columns[i].trim()
@@ -631,18 +733,25 @@ var textAuthor = function (state) {
631
733
  tokenAuthorColumn.type = 'author_column';
632
734
  tokenAuthorColumn.content = column;
633
735
  tokenAuthorColumn.children = [];
634
- var colArr = column.split('\\\\');
736
+ pos = pos + columns[i].length;
737
+ pos += i < columns.length - 1 ? '\\and'.length : 0;
738
+ tokenAuthorColumn.nextPos = pos;
739
+ var colArr = columns[i].split('\\\\');
740
+ var posCol = 0;
635
741
  if (colArr && colArr.length) {
636
742
  for (var j = 0; j < colArr.length; j++) {
637
743
  var item = colArr[j] ? colArr[j].trim() : '';
638
- var arrItem = item.split('\n');
639
- arrItem = arrItem.map(function (item) { return item.trim(); });
640
- item = arrItem.join(' ');
641
744
  var newToken = {};
642
745
  newToken.type = 'author_item';
643
746
  newToken.content = item;
747
+ newToken.offsetLeft = ((_b = colArr[j].trim()) === null || _b === void 0 ? void 0 : _b.length) ? utils_1.getSpacesFromLeft(colArr[j]) : 0;
748
+ posCol = posCol + colArr[j].length;
749
+ posCol += j < colArr.length - 1 ? '\\\\'.length : 0;
750
+ newToken.nextPos = posCol;
644
751
  var children = [];
752
+ state.env.newlineToSpace = true;
645
753
  state.md.inline.parse(item, state.md, state.env, children);
754
+ state.env.newlineToSpace = true;
646
755
  newToken.children = children;
647
756
  tokenAuthorColumn.children.push(newToken);
648
757
  }
@@ -683,22 +792,33 @@ var textTypes = function (state) {
683
792
  if (!type || type === '') {
684
793
  return false;
685
794
  }
686
- var _b = common_1.findEndMarker(state.src, startPos), _c = _b.res, res = _c === void 0 ? false : _c, _d = _b.content, content = _d === void 0 ? '' : _d, _e = _b.nextPos, nextPos = _e === void 0 ? 0 : _e;
795
+ var _b = common_1.findEndMarker(state.src, startPos), _c = _b.res, res = _c === void 0 ? false : _c, _d = _b.content, content = _d === void 0 ? '' : _d, _e = _b.nextPos, nextPos = _e === void 0 ? 0 : _e, _f = _b.endPos, endPos = _f === void 0 ? 0 : _f;
687
796
  if (!res) {
688
797
  return false;
689
798
  }
690
- state.push(type + '_open', "", 0);
691
- var token = state.push(type, "", 0);
799
+ var token = state.push(type + '_open', "", 0);
800
+ token.inlinePos = {
801
+ start: state.pos,
802
+ end: startPos + 1
803
+ };
804
+ token.nextPos = startPos + 1;
805
+ token = state.push(type, "", 0);
692
806
  if (((_a = state.md.options) === null || _a === void 0 ? void 0 : _a.forDocx) && arrtStyle) {
693
807
  token.attrSet('style', arrtStyle);
694
808
  }
695
809
  token.content = content;
810
+ token.inlinePos = {
811
+ start: startPos + 1,
812
+ end: endPos,
813
+ };
814
+ token.nextPos = endPos;
696
815
  token.children = [];
697
816
  var children = [];
698
817
  state.md.inline.parse(token.content.trim(), state.md, state.env, children);
699
818
  token.children = children;
700
819
  state.push(type + '_close', "", 0);
701
820
  state.pos = nextPos;
821
+ state.nextPos = nextPos;
702
822
  return true;
703
823
  };
704
824
  var pageBreaks = function (state) {
@@ -722,6 +842,28 @@ var pageBreaks = function (state) {
722
842
  state.pos = nextPos;
723
843
  return true;
724
844
  };
845
+ var doubleSlashToSoftBreak = function (state) {
846
+ var startPos = state.pos;
847
+ if (state.src.charCodeAt(startPos) !== 0x5c /* \ */) {
848
+ return false;
849
+ }
850
+ var nextPos = startPos + 1;
851
+ if (state.src.charCodeAt(nextPos) !== 0x5c /* \ */) {
852
+ return false;
853
+ }
854
+ if (state.env.doubleSlashToSoftBreak) {
855
+ var token = state.push('softbreak', 'br', 0);
856
+ token.inlinePos = {
857
+ start: startPos,
858
+ end: nextPos
859
+ };
860
+ state.pos = nextPos + 1;
861
+ return true;
862
+ }
863
+ else {
864
+ return false;
865
+ }
866
+ };
725
867
  var linkifyURL = function (state) {
726
868
  var urlTag = /(?:(www|http:|https:)+[^\s]+[\w])/;
727
869
  var startPos = state.pos;
@@ -747,12 +889,24 @@ var linkifyURL = function (state) {
747
889
  var token;
748
890
  var text = state.src.slice(startPos + 1, nextPos - endMarker.length);
749
891
  if (!text || text.trim().length === 0) {
892
+ token = state.push('textUrl', '', 0);
893
+ token.content = text;
894
+ token.nextPos = nextPos;
895
+ token.inlinePos = {
896
+ start_content: startPos + 1,
897
+ end_content: nextPos - endMarker.length
898
+ };
750
899
  state.pos = nextPos;
751
900
  return true;
752
901
  }
753
902
  if (!state.md.linkify.test(text) || !urlTag.test(text)) {
754
903
  token = state.push('textUrl', '', 0);
755
904
  token.content = text;
905
+ token.nextPos = nextPos;
906
+ token.inlinePos = {
907
+ start_content: startPos + 1,
908
+ end_content: nextPos - endMarker.length
909
+ };
756
910
  state.pos = nextPos;
757
911
  return true;
758
912
  }
@@ -773,11 +927,19 @@ var linkifyURL = function (state) {
773
927
  if (pos > lastPos) {
774
928
  token = state.push('textUrl', '', 0);
775
929
  token.content = text.slice(lastPos, pos);
930
+ token.inlinePos = {
931
+ start_content: lastPos,
932
+ end_content: pos
933
+ };
776
934
  token.level = level;
777
935
  }
778
936
  token = state.push('textUrl', '', 0);
779
937
  lastPos = links[ln].lastIndex;
780
938
  token.content = text.slice(pos, lastPos);
939
+ token.inlinePos = {
940
+ start_content: lastPos,
941
+ end_content: pos
942
+ };
781
943
  token.level = level;
782
944
  continue;
783
945
  }
@@ -794,6 +956,10 @@ var linkifyURL = function (state) {
794
956
  if (pos > lastPos) {
795
957
  token = state.push('textUrl', '', 0);
796
958
  token.content = text.slice(lastPos, pos);
959
+ token.inlinePos = {
960
+ start_content: lastPos,
961
+ end_content: pos
962
+ };
797
963
  token.level = level;
798
964
  }
799
965
  token = state.push('link_open', 'a', 1);
@@ -801,19 +967,27 @@ var linkifyURL = function (state) {
801
967
  token.level = level++;
802
968
  token.markup = 'linkify';
803
969
  token.info = 'auto';
970
+ token.nextPos = startPos + 1;
804
971
  token = state.push('text', '', 0);
805
972
  token.content = urlText;
806
973
  token.level = level;
974
+ token.nextPos = endMarkerPos;
807
975
  token = state.push('link_close', 'a', -1);
808
976
  token.level = --level;
809
977
  token.markup = 'linkify';
810
978
  token.info = 'auto';
979
+ token.nextPos = nextPos;
811
980
  lastPos = links[ln].lastIndex;
812
981
  }
813
982
  if (lastPos < text.length) {
814
983
  token = state.push('textUrl', '', 0);
815
984
  token.content = text.slice(lastPos);
985
+ token.inlinePos = {
986
+ start_content: lastPos,
987
+ end_content: text.length
988
+ };
816
989
  token.level = level;
990
+ state.nextPos = nextPos;
817
991
  }
818
992
  state.pos = nextPos;
819
993
  return true;
@@ -847,40 +1021,55 @@ exports.renderInlineContent = function (token, options, env, slf) {
847
1021
  return token.content;
848
1022
  };
849
1023
  var renderSectionTitle = function (tokens, index, options, env, slf) {
1024
+ var _a;
850
1025
  var token = tokens[index];
851
1026
  var content = exports.renderInlineContent(token, options, env, slf);
852
1027
  if (token.isUnNumbered) {
853
1028
  return content;
854
1029
  }
855
1030
  var label = token.uuid ? labels_1.getLabelByUuidFromLabelsList(token.uuid) : null;
1031
+ var dataAttrsStyle = ((_a = token.highlights) === null || _a === void 0 ? void 0 : _a.length) && token.highlightAll
1032
+ ? common_2.getStyleFromHighlight(token.highlights[0])
1033
+ : '';
1034
+ var style = dataAttrsStyle ? " style=\"" + dataAttrsStyle + "\"" : '';
856
1035
  var sectionNumber = token.is_numerable
857
1036
  ? label
858
- ? "<span id=\"" + label.id + "\" class=\"section-number\">" + token.section + ". </span>"
859
- : "<span class=\"section-number\">" + token.section + ". </span>"
1037
+ ? "<span id=\"" + label.id + "\" class=\"section-number\"" + style + ">" + token.section + ". </span>"
1038
+ : "<span class=\"section-number\"" + style + ">" + token.section + ". </span>"
860
1039
  : "";
861
1040
  return "" + sectionNumber + content;
862
1041
  };
863
1042
  var renderSubsectionTitle = function (tokens, index, options, env, slf) {
1043
+ var _a;
864
1044
  var token = tokens[index];
865
1045
  var content = exports.renderInlineContent(token, options, env, slf);
866
1046
  if (token.isUnNumbered) {
867
1047
  return content;
868
1048
  }
869
1049
  var label = token.uuid ? labels_1.getLabelByUuidFromLabelsList(token.uuid) : null;
1050
+ var dataAttrsStyle = ((_a = token.highlights) === null || _a === void 0 ? void 0 : _a.length) && token.highlightAll
1051
+ ? common_2.getStyleFromHighlight(token.highlights[0])
1052
+ : '';
1053
+ var style = dataAttrsStyle ? " style=\"" + dataAttrsStyle + "\"" : '';
870
1054
  return label
871
- ? "<span id=\"" + label.id + "\" class=\"section-number\">" + token.section + ".</span><span class=\"sub_section-number\">" + token.subsection + ".</span> " + content
872
- : "<span class=\"section-number\">" + token.section + ".</span><span class=\"sub_section-number\">" + token.subsection + ".</span> " + content;
1055
+ ? "<span id=\"" + label.id + "\" class=\"section-number\"" + style + ">" + token.section + ".</span><span class=\"sub_section-number\"" + style + ">" + token.subsection + ".</span> " + content
1056
+ : "<span class=\"section-number\"" + style + ">" + token.section + ".</span><span class=\"sub_section-number\"" + style + ">" + token.subsection + ".</span> " + content;
873
1057
  };
874
1058
  var renderSubSubsectionTitle = function (tokens, index, options, env, slf) {
1059
+ var _a;
875
1060
  var token = tokens[index];
876
1061
  var content = exports.renderInlineContent(token, options, env, slf);
877
1062
  if (token.isUnNumbered) {
878
1063
  return content;
879
1064
  }
880
1065
  var label = token.uuid ? labels_1.getLabelByUuidFromLabelsList(token.uuid) : null;
1066
+ var dataAttrsStyle = ((_a = token.highlights) === null || _a === void 0 ? void 0 : _a.length) && token.highlightAll
1067
+ ? common_2.getStyleFromHighlight(token.highlights[0])
1068
+ : '';
1069
+ var style = dataAttrsStyle ? " style=\"" + dataAttrsStyle + "\"" : '';
881
1070
  return label
882
- ? "<span id=\"" + label.id + "\" class=\"section-number\">" + token.section + ".</span><span class=\"sub_section-number\">" + token.subsection + "." + token.subsubsection + ".</span> " + content
883
- : "<span class=\"section-number\">" + token.section + ".</span><span class=\"sub_section-number\">" + token.subsection + "." + token.subsubsection + ".</span> " + content;
1071
+ ? "<span id=\"" + label.id + "\" class=\"section-number\"" + style + ">" + token.section + ".</span><span class=\"sub_section-number\"" + style + ">" + token.subsection + "." + token.subsubsection + ".</span> " + content
1072
+ : "<span class=\"section-number\"" + style + ">" + token.section + ".</span><span class=\"sub_section-number\"" + style + ">" + token.subsection + "." + token.subsubsection + ".</span> " + content;
884
1073
  };
885
1074
  var getAuthorItemToken = function (tokens, index, options, env, slf) {
886
1075
  var res = '';
@@ -1001,6 +1190,11 @@ exports.default = (function () {
1001
1190
  md.inline.ruler.before("textTypes", "textAuthor", textAuthor);
1002
1191
  md.inline.ruler.before('textTypes', 'linkifyURL', linkifyURL);
1003
1192
  md.inline.ruler.before('textTypes', 'pageBreaks', pageBreaks);
1193
+ md.inline.ruler.before('textTypes', 'doubleSlashToSoftBreak', doubleSlashToSoftBreak);
1194
+ md.inline.ruler.before('newline', 'newlineToSpace', new_line_to_space_1.newlineToSpace);
1195
+ /** ParserInline#ruler2 -> Ruler
1196
+ *[[Ruler]] instance. Second ruler used for post-processing **/
1197
+ md.inline.ruler2.at('text_collapse', text_collapse_1.textCollapse);
1004
1198
  Object.keys(mappingTextStyles).forEach(function (key) {
1005
1199
  md.renderer.rules[key] = function (tokens, idx, options, env, slf) {
1006
1200
  switch (tokens[idx].type) {
@@ -1056,6 +1250,9 @@ exports.default = (function () {
1056
1250
  }
1057
1251
  };
1058
1252
  });
1253
+ md.renderer.rules.flatNewLine = function () {
1254
+ return ' ';
1255
+ };
1059
1256
  md.renderer.rules.pagebreak = function (tokens, idx, options, env, slf) {
1060
1257
  if (env === void 0) { env = {}; }
1061
1258
  return renderPageBreaks(tokens, idx, options, env, slf);