diff options
Diffstat (limited to 'src/theme')
-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に応じて見出しタグをレンダー |