Skip to content

Commit b3a3025

Browse files
committed
feat: 支持通过html_rander标签 对里面的html内容进行渲染
1 parent e8e4db1 commit b3a3025

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

ui/src/components/markdown/MdRenderer.vue

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<el-icon><EditPen /></el-icon>
1010
{{ item.content }}
1111
</div>
12+
<div v-else-if="item.type === 'html_rander'" :innerHTML="item.content"></div>
1213
<MdPreview
1314
v-else
1415
noIconfont
@@ -60,7 +61,7 @@ const md_view_list = computed(() => {
6061
return md_img_list[Math.floor(index / 2)]
6162
}
6263
})
63-
return split_quick_question(result)
64+
return split_html_rander(split_quick_question(result))
6465
})
6566
const split_quick_question = (result: Array<string>) => {
6667
return result
@@ -95,6 +96,40 @@ const split_quick_question_ = (source: string) => {
9596
})
9697
return result
9798
}
99+
const split_html_rander = (result: Array<any>) => {
100+
return result
101+
.map((item) => split_html_rander_(item.content, item.type))
102+
.reduce((x: any, y: any) => {
103+
return [...x, ...y]
104+
}, [])
105+
}
106+
107+
const split_html_rander_ = (source: string, type: string) => {
108+
const temp_md_quick_question_list = source.match(/<html_rander>[\d\D]*?<\/html_rander>/g)
109+
const md_quick_question_list = temp_md_quick_question_list
110+
? temp_md_quick_question_list.filter((i) => i)
111+
: []
112+
const split_quick_question_value = source
113+
.split(/<html_rander>[\d\D]*?<\/html_rander>/g)
114+
.filter((item) => item !== undefined)
115+
.filter((item) => !md_quick_question_list?.includes(item))
116+
const result = Array.from(
117+
{ length: md_quick_question_list.length + split_quick_question_value.length },
118+
(v, i) => i
119+
).map((index) => {
120+
if (index % 2 == 0) {
121+
return { type: type, content: split_quick_question_value[Math.floor(index / 2)] }
122+
} else {
123+
return {
124+
type: 'html_rander',
125+
content: md_quick_question_list[Math.floor(index / 2)]
126+
.replace('<html_rander>', '')
127+
.replace('</html_rander>', '')
128+
}
129+
}
130+
})
131+
return result
132+
}
98133
</script>
99134
<style lang="scss" scoped>
100135
.problem-button {

0 commit comments

Comments
 (0)