|
|
@@ -4138,6 +4138,19 @@ class Markdown {
|
|
4138
|
4138
|
*/
|
|
4139
|
4139
|
toHTML(markdown, elementIdPrefix='') {
|
|
4140
|
4140
|
const lines = markdown.split(/(?:\n|\r|\r\n)/);
|
|
|
4141
|
+ try {
|
|
|
4142
|
+ return this.#parse(lines, elementIdPrefix);
|
|
|
4143
|
+ } catch (e) {
|
|
|
4144
|
+ this.#investigateException(lines, elementIdPrefix);
|
|
|
4145
|
+ throw e;
|
|
|
4146
|
+ }
|
|
|
4147
|
+ }
|
|
|
4148
|
+
|
|
|
4149
|
+ /**
|
|
|
4150
|
+ * @param {string[]} lines
|
|
|
4151
|
+ * @param {string} elementIdPrefix
|
|
|
4152
|
+ */
|
|
|
4153
|
+ #parse(lines, elementIdPrefix) {
|
|
4141
|
4154
|
const state = new MDState(lines);
|
|
4142
|
4155
|
state.readersByBlockPriority = this.#readersByBlockPriority;
|
|
4143
|
4156
|
state.readersByTokenPriority = this.#readersByTokenPriority
|
|
|
@@ -4153,4 +4166,36 @@ class Markdown {
|
|
4153
|
4166
|
}
|
|
4154
|
4167
|
return MDNode.toHTML(nodes, state);
|
|
4155
|
4168
|
}
|
|
|
4169
|
+
|
|
|
4170
|
+ /**
|
|
|
4171
|
+ * Keeps removing first and last lines of markdown to locate the source of
|
|
|
4172
|
+ * an exception.
|
|
|
4173
|
+ *
|
|
|
4174
|
+ * @param {string[]} lines
|
|
|
4175
|
+ * @param {string} elementIdPrefix
|
|
|
4176
|
+ */
|
|
|
4177
|
+ #investigateException(lines, elementIdPrefix) {
|
|
|
4178
|
+ var startIndex = 0;
|
|
|
4179
|
+ var endIndex = lines.length;
|
|
|
4180
|
+ // Keep stripping away first line until an exception stops being thrown
|
|
|
4181
|
+ for (var i = 0; i < lines.length; i++) {
|
|
|
4182
|
+ try {
|
|
|
4183
|
+ this.#parse(lines.slice(i, endIndex), elementIdPrefix);
|
|
|
4184
|
+ break;
|
|
|
4185
|
+ } catch (e0) {
|
|
|
4186
|
+ startIndex = i;
|
|
|
4187
|
+ }
|
|
|
4188
|
+ }
|
|
|
4189
|
+ // Keep stripping away last line until an exception stops being thrown
|
|
|
4190
|
+ for (var i = lines.length; i > startIndex; i--) {
|
|
|
4191
|
+ try {
|
|
|
4192
|
+ this.#parse(lines.slice(startIndex, i), elementIdPrefix);
|
|
|
4193
|
+ break;
|
|
|
4194
|
+ } catch (e0) {
|
|
|
4195
|
+ endIndex = i;
|
|
|
4196
|
+ }
|
|
|
4197
|
+ }
|
|
|
4198
|
+ const problematicMarkdown = lines.slice(startIndex, endIndex).join("\n");
|
|
|
4199
|
+ console.error(`This portion of markdown caused an unexpected exception: ${problematicMarkdown}`);
|
|
|
4200
|
+ }
|
|
4156
|
4201
|
}
|