From 28a8863f4575e5d3f0c312763eef0c9b9bb923ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Mon, 22 Jan 2024 16:03:07 +0100 Subject: [PATCH] Allow for lists inside GitHub alerts when redered in markdown (#19505) * Allow for lists inside GitHub alerts when redered in markdown * simplify --- gallery/src/pages/lovelace/markdown-card.ts | 3 +++ src/components/ha-markdown-element.ts | 17 ++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/gallery/src/pages/lovelace/markdown-card.ts b/gallery/src/pages/lovelace/markdown-card.ts index 576e6189c7..aa47310b52 100644 --- a/gallery/src/pages/lovelace/markdown-card.ts +++ b/gallery/src/pages/lovelace/markdown-card.ts @@ -80,6 +80,9 @@ const CONFIGS = [ > [!CAUTION] > This is a GitHub caution alert + > [!TIP] + > - This is a list entry in GitHub tip alert + ## Lists Unordered diff --git a/src/components/ha-markdown-element.ts b/src/components/ha-markdown-element.ts index e282378ada..cd4e90c0c9 100644 --- a/src/components/ha-markdown-element.ts +++ b/src/components/ha-markdown-element.ts @@ -98,13 +98,16 @@ class HaMarkdownElement extends ReactiveElement { firstElementChild!.childNodes[1].textContent?.trimStart()) || ""; - const childNodes = Array.from(firstElementChild!.childNodes); - for (const child of childNodes.slice( - childNodes.findIndex( - // There is always a line break between the title and the content, we want to skip that - (childNode) => childNode instanceof HTMLBRElement - ) + 1 - )) { + const childNodes = Array.from(node.childNodes) + .map((child) => Array.from(child.childNodes)) + .reduce((acc, val) => acc.concat(val), []) + .filter( + (childNode) => + childNode.textContent && + !(childNode.textContent in _gitHubBlockQuoteToAlert) && + !(childNode.textContent in _legacyGitHubBlockQuoteToAlert) + ); + for (const child of childNodes) { alertNote.appendChild(child); } node.firstElementChild!.replaceWith(alertNote);