feat: implement content reveal mechanism via DOM traversal
Add `addRevealedClasses` to apply `revealed` or `concealed` CSS classes to article elements based on the current heading hierarchy and revealed paths. Update `Article` to expose its DOM element via an `onDom` callback.
This commit is contained in:
@@ -21,6 +21,7 @@ export interface ArticleProps {
|
||||
onError?: (error: Error) => void;
|
||||
class?: string; // 额外的 class 用于样式控制
|
||||
scrollToHash?: boolean; // 是否自动滚动到 hash
|
||||
onDom?: (dom: HTMLDivElement) => void;
|
||||
}
|
||||
|
||||
async function fetchArticleContent(params: {
|
||||
@@ -64,6 +65,7 @@ export const Article: Component<ArticleProps> = (props) => {
|
||||
() => ({ src: props.src, section: props.section }),
|
||||
fetchArticleContent,
|
||||
);
|
||||
let innerDiv!: HTMLDivElement;
|
||||
|
||||
// 解析 iconPath,默认为 "./assets",空字符串表示禁用
|
||||
const iconPrefix = createMemo(() => {
|
||||
@@ -80,6 +82,8 @@ export const Article: Component<ArticleProps> = (props) => {
|
||||
|
||||
// 内容渲染后检查 hash 并滚动
|
||||
scrollToHash(location.hash);
|
||||
|
||||
props.onDom?.(innerDiv);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -101,6 +105,7 @@ export const Article: Component<ArticleProps> = (props) => {
|
||||
<Show when={!content.loading && !content.error && content()}>
|
||||
<div
|
||||
class="relative"
|
||||
ref={innerDiv}
|
||||
innerHTML={parseMarkdown(content()!, iconPrefix())}
|
||||
/>
|
||||
</Show>
|
||||
|
||||
Reference in New Issue
Block a user