|
|
@@ -100,14 +100,59 @@ const props = withDefaults(defineProps<{
|
|
|
});
|
|
|
|
|
|
const tagStyle = inject<Ref<Record<string, string>>>('tagStyle', ref({}));
|
|
|
+const builtInStyles = {
|
|
|
+ // 标题标签
|
|
|
+ 'h1': 'font-size: 2em; font-weight: bold; margin: 0.67em 0;',
|
|
|
+ 'h2': 'font-size: 1.5em; font-weight: bold; margin: 0.83em 0;',
|
|
|
+ 'h3': 'font-size: 1.17em; font-weight: bold; margin: 1em 0;',
|
|
|
+ 'h4': 'font-size: 1em; font-weight: bold; margin: 1.33em 0;',
|
|
|
+ 'h5': 'font-size: 0.83em; font-weight: bold; margin: 1.67em 0;',
|
|
|
+ 'h6': 'font-size: 0.67em; font-weight: bold; margin: 2.33em 0;',
|
|
|
+
|
|
|
+ // 段落和引用
|
|
|
+ 'p': 'margin: 1em 0;',
|
|
|
+ 'blockquote': 'margin: 1em 0; padding: 0 1em; border-left: 4px solid #ddd; color: #666;',
|
|
|
+
|
|
|
+ // 列表
|
|
|
+ 'ul': 'margin: 1em 0; padding-left: 2em;',
|
|
|
+ 'ol': 'margin: 1em 0; padding-left: 2em;',
|
|
|
+ 'li': 'margin: 0.5em 0;',
|
|
|
+
|
|
|
+ // 强调标签
|
|
|
+ 'b': 'font-weight: bold;',
|
|
|
+ 'strong': 'font-weight: bold;',
|
|
|
+ 'i': 'font-style: italic;',
|
|
|
+ 'em': 'font-style: italic;',
|
|
|
+ 'u': 'text-decoration: underline;',
|
|
|
+ 'del': 'text-decoration: line-through;',
|
|
|
+
|
|
|
+ // 代码相关
|
|
|
+ 'code': 'font-family: monospace; background: #f5f5f5; padding: 0.2em 0.4em; border-radius: 3px;',
|
|
|
+ 'pre': 'font-family: monospace; background: #f5f5f5; padding: 1em; border-radius: 3px; overflow: auto;',
|
|
|
+
|
|
|
+ // 其他内联标签
|
|
|
+ 'mark': 'background-color: #ffeb3b; padding: 0.2em;',
|
|
|
+ 'sup': 'font-size: 0.83em; vertical-align: super;',
|
|
|
+ 'sub': 'font-size: 0.83em; vertical-align: sub;',
|
|
|
+ 'small': 'font-size: 0.83em;',
|
|
|
+ 'large': 'font-size: 1.17em;',
|
|
|
+
|
|
|
+ // 分隔线
|
|
|
+ 'hr': 'border: 0; border-top: 1px solid #ddd; margin: 1em 0;'
|
|
|
+} as Record<string, string>;
|
|
|
const style = computed(() =>
|
|
|
[
|
|
|
(props.node.attrs?.style || ''),
|
|
|
+ (builtInStyles[props.node.tag] || ''),
|
|
|
+ isInline.value ? 'display:inline' : '',
|
|
|
(tagStyle.value[props.node.tag] || ''),
|
|
|
- isInline.value ? 'display:inline;' : '',
|
|
|
].join(';'),
|
|
|
);
|
|
|
-const isInline = computed(() => ['span','a','large','small'].includes(props.node.tag));
|
|
|
+const isInline = computed(() => [
|
|
|
+ 'span', 'a', 'large','small',
|
|
|
+ 'i', 'b', 'em', 'strong', 'u', 'del',
|
|
|
+ 'code', 'sup', 'sub', 'mark'
|
|
|
+].includes(props.node.tag));
|
|
|
|
|
|
// 链接点击事件
|
|
|
const linkTap = (e: any) => {
|