Commit 8fe357fc authored by 水玉婷's avatar 水玉婷
Browse files

feat:登陆不取缓存+md处理代码块

parent b36cf82d
...@@ -47,12 +47,12 @@ export default { ...@@ -47,12 +47,12 @@ export default {
} }
onMounted(() => { onMounted(() => {
// 检查是否已登录 // // 检查是否已登录
const status = wechat.checkLoginStatus() // const status = wechat.checkLoginStatus()
if (status.isLoggedIn) { // if (status.isLoggedIn) {
router.replace('/') // router.replace('/')
return // return
} // }
// 执行静默登录 // 执行静默登录
handleLogin() handleLogin()
......
...@@ -26,7 +26,7 @@ const processMarkdownFormat = (text: string): string => { ...@@ -26,7 +26,7 @@ const processMarkdownFormat = (text: string): string => {
processedText = processedText.replace(/~~(.*?)~~/gim, '<del>$1</del>'); processedText = processedText.replace(/~~(.*?)~~/gim, '<del>$1</del>');
// 处理行内代码 // 处理行内代码
processedText = processedText.replace(/`([^`]+)`/gim, '<code>$1</code>'); processedText = processedText.replace(/`([^`\n]+)`/gim, '<code>$1</code>');
return processedText; return processedText;
}; };
...@@ -84,17 +84,16 @@ export const parseMarkdown = (text: string): string => { ...@@ -84,17 +84,16 @@ export const parseMarkdown = (text: string): string => {
// 处理引用块(必须在HTML转义之前,避免>被转义为&gt;) // 处理引用块(必须在HTML转义之前,避免>被转义为&gt;)
// 改进的多行引用块处理,支持连续引用行 // 改进的多行引用块处理,支持连续引用行
text = text.replace(/^>\s*(.*(?:\n>\s*.*)*)$/gim, (match, content) => { text = text.replace(/^>\s*(.*(?:\n>\s*.*)*)$/gim, (_match, content) => {
// 将多行引用内容合并,并用<br>分隔 // 将多行引用内容合并,并用<br>分隔
const lines = content.split(/\n>\s*/); const lines = content.split(/\n>\s*/);
const processedContent = lines.map(line => line.trim()).join('<br/>'); const processedContent = lines.map((line: string) => line.trim()).join('<br/>');
return `<blockquote>${processedContent}</blockquote>`; return `<blockquote>${processedContent}</blockquote>`;
}); });
// 处理图片(必须在任何格式处理之前,避免图片格式被破坏) // 处理图片(必须在任何格式处理之前,避免图片格式被破坏)
text = text.replace(/!\[([^\]]*)\]\(([^\)]+)\)/g, (match, alt, src) => { text = text.replace(/!\[([^\]]*)\]\(([^\)]+)\)/g, (_match, alt, src) => {
const altText = alt || '图片'; const altText = alt || '图片';
const imageId = 'img_' + Math.random().toString(36).substr(2, 9);
return `<div class="markdown-image-container" data-image-src="${src}"> return `<div class="markdown-image-container" data-image-src="${src}">
<img src="${src}" alt="${altText}" style="cursor: pointer;" onclick="window.open('${src}', '_blank')"> <img src="${src}" alt="${altText}" style="cursor: pointer;" onclick="window.open('${src}', '_blank')">
${alt ? `<div class="image-caption">${alt}</div>` : ''} ${alt ? `<div class="image-caption">${alt}</div>` : ''}
...@@ -155,12 +154,12 @@ export const parseMarkdown = (text: string): string => { ...@@ -155,12 +154,12 @@ export const parseMarkdown = (text: string): string => {
} }
}); });
// 使用统一的Markdown格式处理函数处理基础格式(包括标题) // 处理代码块(支持语言标识)- 必须在行内代码处理之前
text = processMarkdownFormat(text);
// 处理代码块(支持语言标识)- 必须在换行处理之前
text = text.replace(/```(\w+)?\n([\s\S]*?)```/gim, '<pre><code class="language-$1">$2</code></pre>'); text = text.replace(/```(\w+)?\n([\s\S]*?)```/gim, '<pre><code class="language-$1">$2</code></pre>');
text = text.replace(/```([\s\S]*?)```/gim, '<pre><code>$1</code></pre>'); text = text.replace(/```\s*([\s\S]*?)```/gim, '<pre><code>$1</code></pre>');
// 使用统一的Markdown格式处理函数处理基础格式(包括标题、行内代码等)
text = processMarkdownFormat(text);
// 处理链接(支持相对路径和绝对路径) // 处理链接(支持相对路径和绝对路径)
text = text.replace(/\[([^\]]+)\]\(([^)]+)\)/gim, (match, text, url) => { text = text.replace(/\[([^\]]+)\]\(([^)]+)\)/gim, (match, text, url) => {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment