From d4fa7a528d34fa0854720ffd3ebfcaa7c78bc167 Mon Sep 17 00:00:00 2001 From: Steve Gilberd Date: Mon, 23 Nov 2020 20:20:58 +1300 Subject: [PATCH] Check for empty keys (fixes #1) --- src/slightly.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/slightly.js b/src/slightly.js index 78a0e39..c6058cc 100644 --- a/src/slightly.js +++ b/src/slightly.js @@ -194,6 +194,7 @@ import MarkdownIt from "markdown-it"; .then(p => { // post-process images p.content.querySelectorAll("img[src*='#']").forEach(img => { + if (img.parentNode.childElementCount === 1) img.parentNode.replaceWith(img); let f = document.createElement("figure"); f.style.maxWidth = img.style.maxWidth; img.style.maxWidth = "100%"; @@ -211,7 +212,9 @@ import MarkdownIt from "markdown-it"; decodeURI(format) .split(";") .forEach(attr => { - let [, key, val] = attr.trim().match(/^(.+?)(?:\s*=\s*(.+))?$/); + let matches = attr.trim().match(/^(.+?)(?:\s*=\s*(.+))?$/); + if (!matches) return; + let [, key, val] = matches; switch (key) { case "left": case "right":