refactor: 收敛重复的 Markdown 渲染与应用状态常量
This commit is contained in:
@@ -16,6 +16,7 @@ import { getFragmentsBySession, updateFragments } from "@/api/reportFragments";
|
||||
import { getExpectation, getReportDraft, getTaskFragments, getTaskReports, upsertExpectation } from "@/api/studySessions";
|
||||
import router from "@/router";
|
||||
import MarkdownRenderer from "@/components/MarkdownRenderer.vue";
|
||||
import { renderMarkdown } from "@/utils/markdown";
|
||||
|
||||
const {
|
||||
fragmentsDialogVisible,
|
||||
@@ -151,28 +152,7 @@ const taskInfo = ref({
|
||||
const editingMaterial = ref(false);
|
||||
const editMaterialContent = ref("");
|
||||
const savingMaterial = ref(false);
|
||||
const materialHtml = computed(() => {
|
||||
const raw = taskInfo.value.materialUrl || "";
|
||||
if (!raw.trim()) return "";
|
||||
let html = raw;
|
||||
const links: string[] = [];
|
||||
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m: string, text: string, url: string) => {
|
||||
const tag = `<a href="${url.replace(/"/g, """)}" target="_blank" rel="noopener">${text}</a>`;
|
||||
links.push(tag);
|
||||
return `__LINK_${links.length - 1}__`;
|
||||
});
|
||||
html = html.replace(/https?:\/\/[^\s)\u3001\uFF09\u300D\u300B<>]+/g, (url) => {
|
||||
const clean = url.replace(/[.。,,;;!!??)】」』\]]+$/, "");
|
||||
const tag = `<a href="${clean.replace(/"/g, """)}" target="_blank" rel="noopener">${clean}</a>`;
|
||||
links.push(tag);
|
||||
return `__LINK_${links.length - 1}__`;
|
||||
});
|
||||
html = html.replace(/\n/g, "<br>");
|
||||
for (let i = 0; i < links.length; i++) {
|
||||
html = html.replace(`__LINK_${i}__`, links[i]);
|
||||
}
|
||||
return html;
|
||||
});
|
||||
const materialHtml = computed(() => renderMarkdown(taskInfo.value.materialUrl || ""));
|
||||
|
||||
function startEditMaterial() {
|
||||
editMaterialContent.value = taskInfo.value.materialUrl;
|
||||
|
||||
Reference in New Issue
Block a user