|
|
@@ -856,6 +856,7 @@ class MDState {
|
|
856
|
856
|
// nodes, until no more substitutions can be made.
|
|
857
|
857
|
var anyChanges = false;
|
|
858
|
858
|
do {
|
|
|
859
|
+ this.checkExecutionTime();
|
|
859
|
860
|
anyChanges = false;
|
|
860
|
861
|
for (const readerTuple of this.root.readersBySubstitutePriority) {
|
|
861
|
862
|
/** @type {number} */
|
|
|
@@ -896,6 +897,21 @@ class MDState {
|
|
896
|
897
|
return nodes;
|
|
897
|
898
|
}
|
|
898
|
899
|
|
|
|
900
|
+ #startTime = performance.now();
|
|
|
901
|
+
|
|
|
902
|
+ /**
|
|
|
903
|
+ * Checks if parsing has taken an excessive length of time. Because I'm not
|
|
|
904
|
+ * fully confident in my loops yet. :)
|
|
|
905
|
+ *
|
|
|
906
|
+ * @param {number} maxSeconds
|
|
|
907
|
+ */
|
|
|
908
|
+ checkExecutionTime(maxSeconds=1.0) {
|
|
|
909
|
+ const elapsed = (performance.now() - this.root.#startTime) / 1000.0;
|
|
|
910
|
+ if (elapsed > maxSeconds) {
|
|
|
911
|
+ throw new Error("Markdown parsing taking too long. Infinite loop?");
|
|
|
912
|
+ }
|
|
|
913
|
+ }
|
|
|
914
|
+
|
|
899
|
915
|
/**
|
|
900
|
916
|
* Mapping of reference symbols to URLs. Used by `MDReferencedLinkReader`
|
|
901
|
917
|
* and `MDReferencedImageReader`.
|
|
|
@@ -2785,6 +2801,7 @@ class MDSimplePairInlineReader extends MDReader {
|
|
2785
|
2801
|
return true;
|
|
2786
|
2802
|
});
|
|
2787
|
2803
|
if (match === null) return false;
|
|
|
2804
|
+ state.checkExecutionTime();
|
|
2788
|
2805
|
let content = (plaintext)
|
|
2789
|
2806
|
? match.contentTokens.map((token) => token.original).join('')
|
|
2790
|
2807
|
: state.tokensToNodes(match.contentTokens);
|