import type {
LynxRenderMatchParams,
LynxRenderParams,
} from '@fluxdown/lynx-plugins/base';
import { Fluxdown } from '@fluxdown/lynx';
import {
BaseLynxRenderPlugin,
createTypeOfSlot,
isElementWithTag,
} from '@fluxdown/lynx-plugins/base';
const Blockquote = /*#__PURE__*/ createTypeOfSlot('Blockquote');
const Paragraph = /*#__PURE__*/ createTypeOfSlot('Paragraph');
function renderNote({
node,
parents,
render,
renderChildren,
}: LynxRenderParams) {
if (!isElementWithTag(node, 'p')) {
return null;
}
return (
<Blockquote current={node} parents={parents} render={render}>
<Paragraph
current={node}
parents={parents}
render={render}
style={{ marginTop: '0px', marginBottom: '0px' }}
>
{renderChildren(node)}
</Paragraph>
</Blockquote>
);
}
class NoteRenderPlugin extends BaseLynxRenderPlugin {
static readonly key = 'render-note';
match({ node }: LynxRenderMatchParams) {
if (!isElementWithTag(node, 'p')) {
return false;
}
const first = node.children[0];
return first?.type === 'text' && first.value.startsWith('提示:');
}
readonly render = renderNote;
}
export function Note() {
return (
<Fluxdown
plugins={{ renders: [NoteRenderPlugin] }}
text="提示:请保存修改。"
/>
);
}