import type {
ReactRenderMatchParams,
ReactRenderParams,
} from '@fluxdown/react-presets/base';
import {
BaseReactRenderPlugin,
createTypeOfSlot,
isElementWithTag,
} from '@fluxdown/react-presets/base';
import { Fluxdown } from 'fluxdown';
const Blockquote = createTypeOfSlot('Blockquote');
class NoteRenderPlugin extends BaseReactRenderPlugin {
static readonly key = 'render-note';
readonly config = { priority: -1 };
match({ node }: ReactRenderMatchParams) {
if (!isElementWithTag(node, 'p')) {
return false;
}
const first = node.children[0];
return first?.type === 'text' && first.value.startsWith('提示:');
}
render({ node, parents, render, renderChildren }: ReactRenderParams) {
if (!isElementWithTag(node, 'p')) {
return null;
}
return (
<Blockquote current={node} parents={parents} render={render}>
{renderChildren(node)}
</Blockquote>
);
}
}
export function Note() {
return (
<Fluxdown
plugins={{ renders: [NoteRenderPlugin] }}
text="提示:请保存修改。"
/>
);
}