From 5038f6e154f21e6c83970ce99c9d0aafcb67ce0f Mon Sep 17 00:00:00 2001 From: David Anson Date: Fri, 13 Jan 2023 19:37:17 -0800 Subject: [PATCH] Work around likely micromark bug in sliceSerialize (link to GitHub issue in code). --- lib/micromark.mjs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/micromark.mjs b/lib/micromark.mjs index 0b74113c..59ee0eca 100644 --- a/lib/micromark.mjs +++ b/lib/micromark.mjs @@ -41,11 +41,15 @@ function micromarkParse(markdown) { const history = [ current ]; for (const event of events) { const [ kind, token, context ] = event; - const { type, start, end, _container } = token; + const { type, start, end } = token; const { "column": startColumn, "line": startLine } = start; const { "column": endColumn, "line": endLine } = end; - // sliceSerialize throws when called for a _container - const text = _container ? null : context.sliceSerialize(token); + let text = null; + try { + text = context.sliceSerialize(token); + } catch { + // https://github.com/micromark/micromark/issues/131 + } if (kind === "enter") { const previous = current; history.push(previous);