1212 :class =" sendMessage && type !== 'log' ? 'cursor' : 'disabled'"
1313 >
1414 <el-space :size =" 8" alignment =" flex-start" >
15- <AppIcon iconName =" app-edit" class =" color-primary" style =" margin-top : 3px ; " ></AppIcon >
15+ <AppIcon iconName =" app-edit" class =" color-primary" style =" margin-top : 3px " ></AppIcon >
1616 {{ item.content }}
1717 </el-space >
1818 </div >
@@ -48,6 +48,7 @@ import HtmlRander from './HtmlRander.vue'
4848import EchartsRander from ' ./EchartsRander.vue'
4949import FormRander from ' ./FormRander.vue'
5050import ReasoningRander from ' ./ReasoningRander.vue'
51+ import { nanoid } from ' nanoid'
5152config ({
5253 markdownItConfig(md ) {
5354 md .renderer .rules .image = (tokens , idx , options , env , self ) => {
@@ -204,16 +205,68 @@ const split_form_rander = (result: Array<any>) => {
204205 return [... x , ... y ]
205206 }, [])
206207}
208+ function extractFormRanderContent(html : string ) {
209+ const results = []
210+ const startTag = ' <form_rander>'
211+ const endTag = ' </form_rander>'
207212
213+ let startIndex = html .indexOf (startTag )
214+
215+ while (startIndex !== - 1 ) {
216+ let endIndex = html .indexOf (endTag , startIndex )
217+ let depth = 1
218+ let tempIndex = startIndex + startTag .length
219+
220+ // 查找匹配的结束标签
221+ while (depth > 0 && tempIndex < html .length ) {
222+ const nextStart = html .indexOf (startTag , tempIndex )
223+ const nextEnd = html .indexOf (endTag , tempIndex )
224+
225+ if (nextStart !== - 1 && nextStart < nextEnd ) {
226+ depth ++
227+ tempIndex = nextStart + startTag .length
228+ } else if (nextEnd !== - 1 ) {
229+ depth --
230+ tempIndex = nextEnd + endTag .length
231+ if (depth === 0 ) {
232+ endIndex = nextEnd
233+ }
234+ } else {
235+ break
236+ }
237+ }
238+
239+ if (endIndex !== - 1 ) {
240+ // 提取内容(去掉开始和结束标签)
241+ const contentStart = startIndex + startTag .length
242+ const content = html .substring (contentStart , endIndex )
243+ results .push (content )
244+ startIndex = html .indexOf (startTag , endIndex + endTag .length )
245+ } else {
246+ break
247+ }
248+ }
249+
250+ return results
251+ }
252+ const _split_form_rander = (source : string , form_rander_list : Array <string >) => {
253+ const uuid = nanoid ()
254+ if (form_rander_list .length > 0 ) {
255+ form_rander_list .forEach ((item ) => {
256+ source = source .replace (` <form_rander>${item }</form_rander> ` , uuid )
257+ })
258+ }
259+ return source
260+ .split (uuid )
261+ .filter ((item ) => item !== undefined )
262+ .filter ((item ) => ! form_rander_list ?.includes (item ))
263+ }
208264const split_form_rander_ = (source : string , type : string ) => {
209- const temp_md_quick_question_list = source . match ( / <form_rander> [ \d\D ] *? < \/ form_rander> / g )
265+ const temp_md_quick_question_list = extractFormRanderContent ( source )
210266 const md_quick_question_list = temp_md_quick_question_list
211267 ? temp_md_quick_question_list .filter ((i ) => i )
212268 : []
213- const split_quick_question_value = source
214- .split (/ <form_rander>[\d\D ] *? <\/ form_rander>/ g )
215- .filter ((item ) => item !== undefined )
216- .filter ((item ) => ! md_quick_question_list ?.includes (item ))
269+ const split_quick_question_value = _split_form_rander (source , md_quick_question_list )
217270 const result = Array .from (
218271 { length: md_quick_question_list .length + split_quick_question_value .length },
219272 (v , i ) => i ,
@@ -223,12 +276,11 @@ const split_form_rander_ = (source: string, type: string) => {
223276 } else {
224277 return {
225278 type: ' form_rander' ,
226- content: md_quick_question_list [Math .floor (index / 2 )]
227- .replace (' <form_rander>' , ' ' )
228- .replace (' </form_rander>' , ' ' ),
279+ content: md_quick_question_list [Math .floor (index / 2 )],
229280 }
230281 }
231282 })
283+
232284 return result
233285}
234286 </script >
0 commit comments