mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-11 14:52:52 +01:00
* fix(remark-excerpt): change loop variable to const for better readability * fix(rehype-component-github-card): correct string quotes for consistency in title element * fix(remark-directive-rehype): update biome-ignore comment for clarity on linting rule * fix(rehype-component-admonition): use optional chaining for properties check and improve formatting * fix(Pagination): improve equality checks and enhance code readability * fix(TOC): correct equality check for consistency in removeTailingHash function * fix(ImageWrapper): update import path to use 'node:path' for consistency * fix(PostCard): update import path to use 'node:path' for consistency
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
/// <reference types="mdast" />
|
|
import { h } from 'hastscript'
|
|
|
|
/**
|
|
* Creates an admonition component.
|
|
*
|
|
* @param {Object} properties - The properties of the component.
|
|
* @param {string} [properties.title] - An optional title.
|
|
* @param {('tip'|'note'|'important'|'caution'|'warning')} type - The admonition type.
|
|
* @param {import('mdast').RootContent[]} children - The children elements of the component.
|
|
* @returns {import('mdast').Parent} The created admonition component.
|
|
*/
|
|
export function AdmonitionComponent(properties, children, type) {
|
|
if (!Array.isArray(children) || children.length === 0)
|
|
return h(
|
|
'div',
|
|
{ class: 'hidden' },
|
|
'Invalid admonition directive. (Admonition directives must be of block type ":::note{name="name"} <content> :::")',
|
|
)
|
|
|
|
let label = null
|
|
if (properties?.['has-directive-label']) {
|
|
label = children[0] // The first child is the label
|
|
// biome-ignore lint/style/noParameterAssign: <explanation>
|
|
children = children.slice(1)
|
|
label.tagName = 'div' // Change the tag <p> to <div>
|
|
}
|
|
|
|
return h("blockquote", { class: `admonition bdm-${type}` }, [
|
|
h('span', { class: "bdm-title" }, label ? label : type.toUpperCase()),
|
|
...children,
|
|
])
|
|
}
|