flat: 暂存
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import MarkdownIt from '@/lib/markdown-it.min.js';
|
||||
// import MarkdownIt from '@/lib/markdown-it.esm.js'
|
||||
import hljs from "@/lib/highlight/highlight-uni.min.js";
|
||||
import parseHtml from '@/lib/html-parser.js';
|
||||
// import DOMPurify from '@/lib/dompurify@3.2.4es.js';
|
||||
@@ -15,15 +14,33 @@ const md = new MarkdownIt({
|
||||
langPrefix: 'language-', // 代码高亮前缀
|
||||
// 如果结果以 <pre ... 开头,内部包装器则会跳过。
|
||||
highlight: function(str, lang) {
|
||||
if (lang === 'job-json') {
|
||||
const result = safeExtractJson(str);
|
||||
const jobId = result.appJobUrl.split('jobId=')[1]
|
||||
return `
|
||||
<a class="custom-card" data-job-id="${jobId}">
|
||||
<div class="card-title">
|
||||
<span class="title-text" >${result.jobTitle}</span>
|
||||
<div class="card-tag">${result.location}</div>
|
||||
</div>
|
||||
<div class="card-company">${result.companyName}</div>
|
||||
<div class="card-info">
|
||||
<div class="info-item">${result.salary}</div>
|
||||
<div class="info-item">${result.education}</div>
|
||||
<div class="info-item">${result.experience}</div>
|
||||
</div>
|
||||
<div class="position-nav"></div>
|
||||
</a>
|
||||
`
|
||||
}
|
||||
// 代码块
|
||||
let preCode = ""
|
||||
try {
|
||||
preCode = hljs.highlightAuto(str).value
|
||||
} catch (err) {
|
||||
preCode = markdownIt.utils.escapeHtml(str);
|
||||
}
|
||||
|
||||
// 以换行进行分割
|
||||
// 按行拆分代码
|
||||
// 以换行进行分割 , 按行拆分代码
|
||||
const lines = preCode.split(/\n/).slice(0, -1);
|
||||
const html = lines
|
||||
.map((line, index) =>
|
||||
@@ -48,10 +65,23 @@ const md = new MarkdownIt({
|
||||
}
|
||||
})
|
||||
|
||||
function safeExtractJson(text) {
|
||||
try {
|
||||
const match = text.match(/\{[\s\S]*?\}/); // 提取第一个完整的 JSON 块
|
||||
if (match) {
|
||||
return JSON.parse(match[0]);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('JSON 解析失败:', e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function parseMarkdown(content) {
|
||||
if (!content) {
|
||||
return //处理特殊情况,比如网络异常导致的响应的 content 的值为空
|
||||
}
|
||||
codeDataList = []
|
||||
const unsafeHtml = md.render(content || '')
|
||||
return unsafeHtml
|
||||
}
|
Reference in New Issue
Block a user