From dfe27f0d47dc7244a65c2e3dbf1f21005e880895 Mon Sep 17 00:00:00 2001 From: 安竹洋平 <61961825+yasutakeyohei@users.noreply.github.com> Date: Thu, 25 Jan 2024 21:27:00 +0900 Subject: titleにHTML等が含まれる場合の処理を追加 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/theme/Admonition/Layout/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/theme/Admonition') diff --git a/src/theme/Admonition/Layout/index.js b/src/theme/Admonition/Layout/index.js index 7bc2802b..14a987b0 100644 --- a/src/theme/Admonition/Layout/index.js +++ b/src/theme/Admonition/Layout/index.js @@ -25,10 +25,18 @@ function AdmonitionContainer({type, className, children}) { ); } function AdmonitionHeading({icon, id, title}) { - // 文字列冒頭の#の数を数える - const depth = title.match ? (title.match(/^#+/) || [''])[0].length : 0; - // #を省いたタイトルを得る - const trimmedTitle = depth > 0 ? title.replace(/^#+/, '').trim() : title; + let depth = 0; + let trimmedTitle = ""; + // titleにHTML等が含まれている場合は文字列ではなく配列になる + if(typeof title === "string") { + // 文字列冒頭の#の数を数える( + depth = title.match ? (title.toString().match(/^#+/) || [''])[0].length : 0; + // #を省いたタイトルを得る + trimmedTitle = depth > 0 ? title.replace(/^#+/, '').trim() : title; + } else if (typeof title[0] === "string") { + depth = title[0].match ? (title[0].match(/^#+/) || [''])[0].length : 0; + trimmedTitle = depth > 0 ? [title[0].replace(/^#+/, '').trim(), ...title.slice(1)] : title; + } // スクロール位置調整のcss const classNames = clsx("anchor", "title", headingStyles.anchorWithStickyNavbar); // depthに応じて見出しタグをレンダー -- cgit v1.2.3-54-g00ecf