不再使用markdown编译html,而是直接markdown源文件,前端进行渲染
This commit is contained in:
@@ -235,13 +235,46 @@
|
||||
fetch(`/${course_id}-${chapter_name}-${lesson_name}-markdown`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.html_url) {
|
||||
document.getElementById('markdown-content').innerHTML = `<iframe id="markdown-content-iframe" src="${data.html_url}"style="width: 100%;height: 100%;"></iframe>`;
|
||||
document.getElementById('markdown-content-iframe').addEventListener('load', function() {
|
||||
// 在这里执行你想要的操作
|
||||
console.log('Iframe has finished loading');
|
||||
if (data.markdown_content) {
|
||||
// 使用 marked 解析 Markdown 内容
|
||||
const html = marked.parse(data.markdown_content);
|
||||
|
||||
// 创建包含 MathJax 支持的 HTML 结构
|
||||
const markdownContainer = document.createElement('div');
|
||||
markdownContainer.id = 'markdown-content-container';
|
||||
markdownContainer.innerHTML = html;
|
||||
|
||||
// 清空内容容器并添加渲染后的内容
|
||||
const contentElement = document.getElementById('markdown-content');
|
||||
contentElement.innerHTML = '';
|
||||
contentElement.appendChild(markdownContainer);
|
||||
|
||||
// 配置并加载 MathJax
|
||||
if (typeof MathJax === 'undefined') {
|
||||
// 动态加载 MathJax
|
||||
const script = document.createElement('script');
|
||||
script.src = '/static/cdnback/js/tex-mml-chtml.js';
|
||||
script.async = true;
|
||||
script.onload = function() {
|
||||
MathJax.config = {
|
||||
tex: {
|
||||
inlineMath: [['$', '$'], ['\\(', '\\)']]
|
||||
},
|
||||
svg: {
|
||||
fontCache: 'global'
|
||||
}
|
||||
};
|
||||
MathJax.typesetPromise([markdownContainer]);
|
||||
// 初始化课程进度
|
||||
next_chapter();
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
} else {
|
||||
// MathJax 已加载,直接排版
|
||||
MathJax.typesetPromise([markdownContainer]);
|
||||
// 初始化课程进度
|
||||
next_chapter();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.error('Markdown file not found');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user