@@ -32,6 +32,17 @@ import HtmlRander from './HtmlRander.vue'
32
32
import EchartsRander from ' ./EchartsRander.vue'
33
33
config ({
34
34
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
+ }
35
46
md .renderer .rules .link_open = (tokens , idx , options , env , self ) => {
36
47
tokens [idx ].attrSet (' target' , ' _blank' )
37
48
return md .renderer .renderToken (tokens , idx , options )
@@ -52,51 +63,9 @@ const props = withDefaults(
52
63
const editorRef = ref ()
53
64
const md_view_list = computed (() => {
54
65
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 ])))
72
67
})
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
- }
80
68
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
- }
100
69
const split_quick_question = (result : Array <string >) => {
101
70
return result
102
71
.map ((item ) => split_quick_question_ (item ))
0 commit comments