Compare commits
3 Commits
cb57af854f
...
cf2a3ba19a
| Author | SHA1 | Date | |
|---|---|---|---|
| cf2a3ba19a | |||
| 5072dc92a3 | |||
| 317f7d01dd |
@ -1,7 +1,10 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view v-for="item in recommendThemeList" :key="item.themeName">
|
||||
<RecommendPostsList :recommendTheme="item" />
|
||||
<RecommendPostsList
|
||||
v-if="item.recommendPostsList.length > 0"
|
||||
:recommendTheme="item"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -13,7 +13,26 @@ function Markdown (vm) {
|
||||
|
||||
Markdown.prototype.onUpdate = function (content) {
|
||||
if (this.vm.markdown) {
|
||||
return marked(content)
|
||||
// return marked(content)
|
||||
// 先处理内容,确保只有双波浪号才被解析为删除线
|
||||
// 使用临时占位符保护单个波浪号
|
||||
let processedContent = content;
|
||||
|
||||
// 1. 先保护双波浪号删除线语法
|
||||
processedContent = processedContent.replace(/~~([^~]+?)~~/g, '__STRIKETHROUGH_START__$1__STRIKETHROUGH_END__');
|
||||
|
||||
// 2. 将剩余的单个波浪号转换为HTML实体
|
||||
processedContent = processedContent.replace(/~/g, '~');
|
||||
|
||||
// 3. 恢复双波浪号删除线语法
|
||||
processedContent = processedContent.replace(/__STRIKETHROUGH_START__/g, '~~').replace(/__STRIKETHROUGH_END__/g, '~~');
|
||||
|
||||
return marked(processedContent, {
|
||||
gfm: true,
|
||||
breaks: false,
|
||||
pedantic: false,
|
||||
sanitize: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,79 +1,85 @@
|
||||
<template>
|
||||
<view class="zero-markdown-view">
|
||||
<mp-html :key="mpkey" :selectable="selectable" :scroll-table='scrollTable' :tag-style="tagStyle"
|
||||
:markdown="true" :content="contentAi">
|
||||
<mp-html
|
||||
:key="mpkey"
|
||||
:selectable="selectable"
|
||||
:scroll-table="scrollTable"
|
||||
:tag-style="tagStyle"
|
||||
:markdown="true"
|
||||
:content="contentAi"
|
||||
>
|
||||
</mp-html>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import mpHtml from '../mp-html/mp-html';
|
||||
|
||||
import mpHtml from "../mp-html/mp-html";
|
||||
|
||||
export default {
|
||||
name: 'zero-markdown-view',
|
||||
name: "zero-markdown-view",
|
||||
components: {
|
||||
mpHtml
|
||||
mpHtml,
|
||||
},
|
||||
props: {
|
||||
markdown: {
|
||||
type: String,
|
||||
default: ''
|
||||
default: "",
|
||||
},
|
||||
selectable: {
|
||||
type: [Boolean, String],
|
||||
default: true
|
||||
default: true,
|
||||
},
|
||||
scrollTable: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
default: true,
|
||||
},
|
||||
themeColor: {
|
||||
type: String,
|
||||
default: '#00A6FF'
|
||||
default: "#00A6FF",
|
||||
},
|
||||
codeBgColor: {
|
||||
type: String,
|
||||
default: '#2d2d2d'
|
||||
default: "#2d2d2d",
|
||||
},
|
||||
fontFamily: {
|
||||
type: String,
|
||||
default: 'PingFang SC, PingFang SC'
|
||||
default: "PingFang SC, PingFang SC",
|
||||
},
|
||||
aiMode: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
content: '',
|
||||
tagStyle: '',
|
||||
mpkey: 'zero'
|
||||
content: "",
|
||||
tagStyle: "",
|
||||
mpkey: "zero",
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
contentAi() {
|
||||
if (!this.content) {
|
||||
return //处理特殊情况,比如网络异常导致的响应的 content 的值为空
|
||||
return; //处理特殊情况,比如网络异常导致的响应的 content 的值为空
|
||||
}
|
||||
let htmlString = ''
|
||||
let htmlString = "";
|
||||
// 检查是否有未闭合的代码块
|
||||
const codeBlocks = this.content.match(/```[\s\S]*?```|```[\s\S]*?$/g) || []
|
||||
const lastBlock = codeBlocks[codeBlocks.length - 1]
|
||||
if (lastBlock && !lastBlock.endsWith('```')) {
|
||||
const codeBlocks =
|
||||
this.content.match(/```[\s\S]*?```|```[\s\S]*?$/g) || [];
|
||||
const lastBlock = codeBlocks[codeBlocks.length - 1];
|
||||
if (lastBlock && !lastBlock.endsWith("```")) {
|
||||
// 最后一个代码块未闭合,需要补上结束标识符
|
||||
htmlString = this.content + '\n'
|
||||
htmlString = this.content + "\n";
|
||||
} else {
|
||||
htmlString = this.content
|
||||
htmlString = this.content;
|
||||
}
|
||||
return htmlString
|
||||
return htmlString;
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
markdown: function (val) {
|
||||
this.content = this.markdown
|
||||
}
|
||||
this.content = this.markdown;
|
||||
},
|
||||
},
|
||||
created() {
|
||||
if (this.aiMode) {
|
||||
@ -83,15 +89,14 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.content = this.markdown
|
||||
this.content = this.markdown;
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
initTagStyle() {
|
||||
const themeColor = this.themeColor
|
||||
const codeBgColor = this.codeBgColor
|
||||
const fontFamily = this.fontFamily
|
||||
const themeColor = this.themeColor;
|
||||
const codeBgColor = this.codeBgColor;
|
||||
const fontFamily = this.fontFamily;
|
||||
let zeroStyle = {
|
||||
p: `
|
||||
margin:4px 0;
|
||||
@ -199,13 +204,13 @@ export default {
|
||||
font-size:12px;
|
||||
position: relative;
|
||||
`,
|
||||
}
|
||||
this.tagStyle = zeroStyle
|
||||
};
|
||||
this.tagStyle = zeroStyle;
|
||||
},
|
||||
initTagStyleForAi() {
|
||||
const themeColor = this.themeColor
|
||||
const codeBgColor = this.codeBgColor
|
||||
const fontFamily = this.fontFamily
|
||||
const themeColor = this.themeColor;
|
||||
const codeBgColor = this.codeBgColor;
|
||||
const fontFamily = this.fontFamily;
|
||||
let zeroStyle = {
|
||||
p: `
|
||||
margin:4px 0;
|
||||
@ -321,10 +326,10 @@ export default {
|
||||
position: relative;
|
||||
font-family: ${fontFamily};
|
||||
`,
|
||||
}
|
||||
this.tagStyle = zeroStyle
|
||||
};
|
||||
this.tagStyle = zeroStyle;
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user