- 网站内容展示:首页, 产品页, 解决方案, 联系信息等 - 网站跳转逻辑:通过Vue-Router实现路由跳转 - 后端通信: 通过Nuxt Strapi与后端Strapi服务进行通信
34 lines
860 B
TypeScript
34 lines
860 B
TypeScript
import MarkdownIt from 'markdown-it';
|
|
|
|
const md = new MarkdownIt({
|
|
html: true,
|
|
linkify: true,
|
|
typographer: true,
|
|
breaks: true,
|
|
})
|
|
|
|
export function renderMarkdown(content: string): string {
|
|
const dirtyHtml = md.render(content);
|
|
|
|
if (typeof window !== 'undefined') {
|
|
import('dompurify').then((DOMPurify => {
|
|
return DOMPurify.default.sanitize(dirtyHtml)
|
|
}))
|
|
}
|
|
|
|
return dirtyHtml
|
|
}
|
|
|
|
export function convertMedia(content: string): string {
|
|
// 通过正则表达式替换Markdown中的图片链接
|
|
//  -> )
|
|
|
|
if(!content) return '';
|
|
|
|
const contentWithAbsoluteUrls = content.replace(
|
|
/!\[([^\]]*)\]\((\/uploads\/[^)]+)\)/g,
|
|
(_, alt, url) => `})`
|
|
)
|
|
|
|
return contentWithAbsoluteUrls;
|
|
} |