Selaa lähdekoodia

修改ai应用图片展示

11wqe1 1 kuukausi sitten
vanhempi
commit
9b628829fc
1 muutettua tiedostoa jossa 18 lisäystä ja 4 poistoa
  1. 18 4
      src/components/components/cocoFlowDia.vue

+ 18 - 4
src/components/components/cocoFlowDia.vue

@@ -74,14 +74,28 @@ import MarkdownIt from "markdown-it";
             },
             MarkdownT() {
                 return function (c) {
+                    
                     let md = new MarkdownIt({
                         html: true, // 允许渲染 HTML
-                        linkify: true, // 自动将URL链接转化为可点击链接
+                        linkify: true, // 自动将URL链接转化为可点击链接 
                         typographer: true, // 启用排版规则(如替换 `"` 为 “)
                     });
-                    return c
-                    ? md.render(c) : "";
-                };
+                    const renderedContent = c ? md.render(c) : "";
+
+                    // 使用正则表达式替换链接
+                    const result = renderedContent.replace(/<a href="([^"]+)">([^<]*)<\/a>/g, (match, url, text) => {
+                        // 判断链接是否为图片格式
+                        if (/\.(png|jpg|jpeg|gif|bmp|svg)$/i.test(url)) {
+                            // 返回<img>标签
+                            return `<img src="${url}" alt="${text}" />`;
+                        } else {
+                            // 返回原来的<a>标签
+                            return match;
+                        }
+                    });
+
+                    return result;
+                }
             }
         },
         methods: {