feat: markdown 样式调整
This commit is contained in:
@@ -1,79 +1,85 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="zero-markdown-view">
|
<view class="zero-markdown-view">
|
||||||
<mp-html :key="mpkey" :selectable="selectable" :scroll-table='scrollTable' :tag-style="tagStyle"
|
<mp-html
|
||||||
:markdown="true" :content="contentAi">
|
:key="mpkey"
|
||||||
|
:selectable="selectable"
|
||||||
|
:scroll-table="scrollTable"
|
||||||
|
:tag-style="tagStyle"
|
||||||
|
:markdown="true"
|
||||||
|
:content="contentAi"
|
||||||
|
>
|
||||||
</mp-html>
|
</mp-html>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import mpHtml from '../mp-html/mp-html';
|
import mpHtml from "../mp-html/mp-html";
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'zero-markdown-view',
|
name: "zero-markdown-view",
|
||||||
components: {
|
components: {
|
||||||
mpHtml
|
mpHtml,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
markdown: {
|
markdown: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: "",
|
||||||
},
|
},
|
||||||
selectable: {
|
selectable: {
|
||||||
type: [Boolean, String],
|
type: [Boolean, String],
|
||||||
default: true
|
default: true,
|
||||||
},
|
},
|
||||||
scrollTable: {
|
scrollTable: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true,
|
||||||
},
|
},
|
||||||
themeColor: {
|
themeColor: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '#00A6FF'
|
default: "#00A6FF",
|
||||||
},
|
},
|
||||||
codeBgColor: {
|
codeBgColor: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '#2d2d2d'
|
default: "#2d2d2d",
|
||||||
},
|
},
|
||||||
fontFamily: {
|
fontFamily: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'PingFang SC, PingFang SC'
|
default: "PingFang SC, PingFang SC",
|
||||||
},
|
},
|
||||||
aiMode: {
|
aiMode: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
content: '',
|
content: "",
|
||||||
tagStyle: '',
|
tagStyle: "",
|
||||||
mpkey: 'zero'
|
mpkey: "zero",
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
contentAi() {
|
contentAi() {
|
||||||
if (!this.content) {
|
if (!this.content) {
|
||||||
return //处理特殊情况,比如网络异常导致的响应的 content 的值为空
|
return; //处理特殊情况,比如网络异常导致的响应的 content 的值为空
|
||||||
}
|
}
|
||||||
let htmlString = ''
|
let htmlString = "";
|
||||||
// 检查是否有未闭合的代码块
|
// 检查是否有未闭合的代码块
|
||||||
const codeBlocks = this.content.match(/```[\s\S]*?```|```[\s\S]*?$/g) || []
|
const codeBlocks =
|
||||||
const lastBlock = codeBlocks[codeBlocks.length - 1]
|
this.content.match(/```[\s\S]*?```|```[\s\S]*?$/g) || [];
|
||||||
if (lastBlock && !lastBlock.endsWith('```')) {
|
const lastBlock = codeBlocks[codeBlocks.length - 1];
|
||||||
|
if (lastBlock && !lastBlock.endsWith("```")) {
|
||||||
// 最后一个代码块未闭合,需要补上结束标识符
|
// 最后一个代码块未闭合,需要补上结束标识符
|
||||||
htmlString = this.content + '\n'
|
htmlString = this.content + "\n";
|
||||||
} else {
|
} else {
|
||||||
htmlString = this.content
|
htmlString = this.content;
|
||||||
}
|
}
|
||||||
return htmlString
|
return htmlString;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
markdown: function (val) {
|
markdown: function (val) {
|
||||||
this.content = this.markdown
|
this.content = this.markdown;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
if (this.aiMode) {
|
if (this.aiMode) {
|
||||||
@@ -83,15 +89,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.content = this.markdown
|
this.content = this.markdown;
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
initTagStyle() {
|
initTagStyle() {
|
||||||
const themeColor = this.themeColor
|
const themeColor = this.themeColor;
|
||||||
const codeBgColor = this.codeBgColor
|
const codeBgColor = this.codeBgColor;
|
||||||
const fontFamily = this.fontFamily
|
const fontFamily = this.fontFamily;
|
||||||
let zeroStyle = {
|
let zeroStyle = {
|
||||||
p: `
|
p: `
|
||||||
margin:4px 0;
|
margin:4px 0;
|
||||||
@@ -199,13 +204,13 @@ export default {
|
|||||||
font-size:12px;
|
font-size:12px;
|
||||||
position: relative;
|
position: relative;
|
||||||
`,
|
`,
|
||||||
}
|
};
|
||||||
this.tagStyle = zeroStyle
|
this.tagStyle = zeroStyle;
|
||||||
},
|
},
|
||||||
initTagStyleForAi() {
|
initTagStyleForAi() {
|
||||||
const themeColor = this.themeColor
|
const themeColor = this.themeColor;
|
||||||
const codeBgColor = this.codeBgColor
|
const codeBgColor = this.codeBgColor;
|
||||||
const fontFamily = this.fontFamily
|
const fontFamily = this.fontFamily;
|
||||||
let zeroStyle = {
|
let zeroStyle = {
|
||||||
p: `
|
p: `
|
||||||
margin:4px 0;
|
margin:4px 0;
|
||||||
@@ -321,10 +326,10 @@ export default {
|
|||||||
position: relative;
|
position: relative;
|
||||||
font-family: ${fontFamily};
|
font-family: ${fontFamily};
|
||||||
`,
|
`,
|
||||||
}
|
};
|
||||||
this.tagStyle = zeroStyle
|
this.tagStyle = zeroStyle;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user