refactor: 将页面的Markdown渲染改为HTML渲染 #79
@ -13,11 +13,8 @@
|
|||||||
|
|
||||||
const props = defineProps<Props>();
|
const props = defineProps<Props>();
|
||||||
|
|
||||||
const contentWithAbsoluteUrls = convertMedia(props.content);
|
|
||||||
|
|
||||||
// 将 Markdown 转换成 HTML
|
// 将 Markdown 转换成 HTML
|
||||||
const safeHtml = computed(() => renderMarkdown(contentWithAbsoluteUrls));
|
const safeHtml = computed(() => renderMarkdown(props.content));
|
||||||
// const safeHtml = computed(() => renderMarkdown(props.content))
|
|
||||||
|
|
||||||
const container = ref<HTMLElement | null>(null);
|
const container = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
|||||||
@ -18,17 +18,3 @@ export function renderMarkdown(content: string): string {
|
|||||||
|
|
||||||
return dirtyHtml;
|
return dirtyHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertMedia(content: string): string {
|
|
||||||
// 通过正则表达式替换Markdown中的图片链接
|
|
||||||
//  -> )
|
|
||||||
|
|
||||||
if (!content) return '';
|
|
||||||
|
|
||||||
const contentWithAbsoluteUrls = content.replace(
|
|
||||||
/!\[([^\]]*)\]\((\/uploads\/[^)]+)\)/g,
|
|
||||||
(_, alt, url) => `})`
|
|
||||||
);
|
|
||||||
|
|
||||||
return contentWithAbsoluteUrls;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
import { pinyin } from 'pinyin-pro';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将汉语文本转换为拼音形式
|
|
||||||
*/
|
|
||||||
export function transliterateText(input: string): string {
|
|
||||||
if (!input) return '';
|
|
||||||
const text = input.normalize('NFKC').trim();
|
|
||||||
|
|
||||||
// 检测是否包含中文字符
|
|
||||||
if (/[\u4e00-\u9fa5]/.test(text)) {
|
|
||||||
return pinyin(text, { toneType: 'none', type: 'array' }).join('');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 否则返回原文本
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user