diff --git a/app/assets/css/typography.css b/app/assets/css/typography.css new file mode 100644 index 0000000..62b3f10 --- /dev/null +++ b/app/assets/css/typography.css @@ -0,0 +1,53 @@ +.html-typography { + padding: 10px; + line-height: 1.6; +} + +.html-typography h1 { + color: var(--el-color-primary); + font-size: 1.5em; + margin-bottom: 0.5em; + text-align: center; +} + +.html-typography h2 { + color: var(--el-color-primary); + font-size: 1.5em; + margin-bottom: 0.5em; +} + +.html-typography h3 { + color: var(--el-color-primary); + font-size: 1.2em; + margin-bottom: 0.5em; +} + +.html-typography p { + text-indent: 2em; + text-align: justify; + margin: 0.5em 0; + margin-bottom: 1em; +} + +.html-typography ol { + list-style-type: decimal; + padding-left: 2em; + margin-bottom: 1em; +} + +.html-typography ul { + list-style-type: disc; + padding-left: 2em; + margin-bottom: 1em; +} + +.html-typography hr { + border: none; + border-top: 1px solid var(--el-border-color); + margin: 20px 0; +} + +.html-typography table { + width: 100%; + border: 1px solid var(--el-border-color); +} diff --git a/app/components/shared/HtmlRenderer.ts b/app/components/shared/HtmlRenderer.ts new file mode 100644 index 0000000..3cae08c --- /dev/null +++ b/app/components/shared/HtmlRenderer.ts @@ -0,0 +1,30 @@ +export default defineComponent({ + name: 'HtmlRenderer', + + props: { + html: { + type: String, + required: true, + }, + map: { + type: Object as () => HtmlRenderMap, + default: () => defaultHtmlRenderMap, + }, + allowUnknown: { + type: Boolean, + default: true, + }, + }, + + setup(props, { attrs }) { + const nodes: VNode[] = useHtmlRenderer(props.html, { + map: props.map, + allowUnknownTags: props.allowUnknown, + }); + + logger.debug('nodes: ', nodes); + + // 渲染函数:直接返回 VNode 数组 + return () => h('div', { ...attrs }, nodes); + }, +}); diff --git a/app/components/shared/QuestionList.vue b/app/components/shared/QuestionList.vue index cb64b07..c0d93db 100644 --- a/app/components/shared/QuestionList.vue +++ b/app/components/shared/QuestionList.vue @@ -8,7 +8,14 @@ :title="question.title" :name="question.id" > - + +
+
+ +
@@ -25,6 +32,8 @@ const activeNames = ref<(string | number)[]>([]); + const hydrated = ref(false); + // 当路由变化(包括初次挂载)时,检查是否需要聚焦 watch( () => route.query.focus, @@ -47,6 +56,10 @@ }, { immediate: true } ); + + onMounted(() => { + hydrated.value = true; + });