diff options
author | 安竹洋平 <61961825+yasutakeyohei@users.noreply.github.com> | 2024-01-25 21:27:00 +0900 |
---|---|---|
committer | 安竹洋平 <61961825+yasutakeyohei@users.noreply.github.com> | 2024-01-25 21:27:00 +0900 |
commit | dfe27f0d47dc7244a65c2e3dbf1f21005e880895 (patch) | |
tree | 7b55b3c04ed2c3a9bc7cc6d5a84adc580d18ec91 /src | |
parent | fd8b0b8edc700086a4d40c1a105b6965717c04ff (diff) |
titleにHTML等が含まれる場合の処理を追加
Diffstat (limited to 'src')
-rw-r--r-- | src/theme/Admonition/Layout/index.js | 16 |
1 files changed, 12 insertions, 4 deletions
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に応じて見出しタグをレンダー |