feat: 完成网站前端的基本建设
- 网站内容展示:首页, 产品页, 解决方案, 联系信息等 - 网站跳转逻辑:通过Vue-Router实现路由跳转 - 后端通信: 通过Nuxt Strapi与后端Strapi服务进行通信
This commit is contained in:
34
app/utils/markdown.ts
Normal file
34
app/utils/markdown.ts
Normal file
@ -0,0 +1,34 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user