@@ -32,6 +32,17 @@ import HtmlRander from './HtmlRander.vue'
3232import EchartsRander from ' ./EchartsRander.vue'
3333config ({
3434 markdownItConfig(md ) {
35+ md .renderer .rules .image = (tokens , idx , options , env , self ) => {
36+ tokens [idx ].attrSet (' style' , ' display:inline-block;min-height:33px;padding:0;margin:0' )
37+ if (tokens [idx ].content ) {
38+ tokens [idx ].attrSet (' title' , tokens [idx ].content )
39+ }
40+ tokens [idx ].attrSet (
41+ ' onerror' ,
42+ ' this.src="/ui/assets/load_error.png";this.onerror=null;this.height="33px"'
43+ )
44+ return md .renderer .renderToken (tokens , idx , options )
45+ }
3546 md .renderer .rules .link_open = (tokens , idx , options , env , self ) => {
3647 tokens [idx ].attrSet (' target' , ' _blank' )
3748 return md .renderer .renderToken (tokens , idx , options )
@@ -52,51 +63,9 @@ const props = withDefaults(
5263const editorRef = ref ()
5364const md_view_list = computed (() => {
5465 const temp_source = props .source
55- const temp_md_img_list = temp_source .match (/ (!\[ . *? \]\( img\/ . *? \) {. *? })| (!\[ . *? \]\( img\/ . *? \) )/ g )
56- const md_img_list = temp_md_img_list ? temp_md_img_list .filter ((i ) => i ) : []
57- const split_img_value = temp_source
58- .split (/ (!\[ . *? \]\( img\/ . *? \) {. *? })| (!\[ . *? \]\( img\/ . *? \) )/ g )
59- .filter ((item ) => item !== undefined )
60- .filter ((item ) => ! md_img_list ?.includes (item ))
61- const result = Array .from (
62- { length: md_img_list .length + split_img_value .length },
63- (v , i ) => i
64- ).map ((index ) => {
65- if (index % 2 == 0 ) {
66- return split_img_value [Math .floor (index / 2 )]
67- } else {
68- return md_img_list [Math .floor (index / 2 )]
69- }
70- })
71- return split_echarts_rander (split_html_rander (split_quick_question (split_md_img (result ))))
66+ return split_echarts_rander (split_html_rander (split_quick_question ([temp_source ])))
7267})
73- const split_md_img = (result : Array <string >) => {
74- return result
75- .map ((item ) => split_md_img_ (item ))
76- .reduce ((x : any , y : any ) => {
77- return [... x , ... y ]
78- }, [])
79- }
8068
81- const split_md_img_ = (source : string ) => {
82- const temp_md_img_list = source .match (/ (!\[ . *? \]\( . *? \) {. *? })| (!\[ . *? \]\( . *? \) )/ g )
83- const md_img_list = temp_md_img_list ? temp_md_img_list .filter ((i ) => i ) : []
84- const split_img_value = source
85- .split (/ (!\[ . *? \]\( . *? \) {. *? })| (!\[ . *? \]\( . *? \) )/ g )
86- .filter ((item ) => item !== undefined )
87- .filter ((item ) => ! md_img_list ?.includes (item ))
88- const result = Array .from (
89- { length: md_img_list .length + split_img_value .length },
90- (v , i ) => i
91- ).map ((index ) => {
92- if (index % 2 == 0 ) {
93- return split_img_value [Math .floor (index / 2 )]
94- } else {
95- return md_img_list [Math .floor (index / 2 )]
96- }
97- })
98- return result
99- }
10069const split_quick_question = (result : Array <string >) => {
10170 return result
10271 .map ((item ) => split_quick_question_ (item ))
0 commit comments