fix: fix errors and reformat code

This commit is contained in:
saicaca
2024-08-03 16:40:20 +08:00
parent 1f93499ece
commit 0ad144add3
44 changed files with 550 additions and 558 deletions

View File

@@ -11,21 +11,22 @@ import { h } from 'hastscript'
* @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> :::")'
);
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 && properties['has-directive-label']) {
label = children[0]; // The first child is the label
children = children.slice(1);
label.tagName = "div"; // Change the tag <p> to <div>
label = children[0] // The first child is the label
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]
);
}
return h(`blockquote`, { class: `admonition bdm-${type}` }, [
h('span', { class: `bdm-title` }, label ? label : type.toUpperCase()),
...children,
])
}