feat: 更新问题页面和提交页面,集成Vditor适配器,优化Markdown渲染

This commit is contained in:
2026-04-10 15:47:26 +08:00
parent 0c7297afd7
commit 40b77471b5
35 changed files with 1996 additions and 1004 deletions

View File

@@ -115,8 +115,33 @@ include_once("kindeditor.php") ;
</div>
<script src="<?php echo $OJ_CDN_URL."/template/bs3/"?>marked.min.js"></script>
<script>
function typesetPreviewMath(frameWindow) {
if (!frameWindow || !frameWindow.MathJax) {
return Promise.resolve();
}
if (typeof frameWindow.MathJax.typesetPromise === 'function') {
return frameWindow.MathJax.typesetPromise();
}
if (typeof frameWindow.MathJax.typeset === 'function') {
frameWindow.MathJax.typeset();
}
return Promise.resolve();
}
function renderPreviewMarkdown(frameWindow) {
let renderTask = Promise.resolve();
if (!frameWindow) {
return renderTask;
}
if (typeof frameWindow.renderProblemMarkdown === 'function') {
renderTask = Promise.resolve(frameWindow.renderProblemMarkdown());
} else if (frameWindow.HustOJVditor && typeof frameWindow.HustOJVditor.renderMarkdownBlocks === 'function') {
renderTask = frameWindow.HustOJVditor.renderMarkdownBlocks(frameWindow.document.querySelectorAll('.md'));
}
return renderTask.then(function () {
return typesetPreviewMath(frameWindow);
});
}
function transform(){
let height=document.body.clientHeight;
let width=parseInt(document.body.clientWidth*0.6);
@@ -159,20 +184,11 @@ include_once("kindeditor.php") ;
let description=$("textarea").eq(1).val();
preview.find("#description").html(description);
preview.find("#description .md").each(function(){
$(this).html(marked.parse($(this).html()));
});
let input=$("textarea").eq(3).val();
preview.find("#input").html(input);
preview.find("#input .md").each(function(){
$(this).html(marked.parse($(this).html()));
});
let output=$("textarea").eq(5).val();
preview.find("#output").html(output);
preview.find("#output .md").each(function(){
$(this).html(marked.parse($(this).html()));
});
let sinput=$("textarea").eq(6).val();
preview.find("#sinput").html(sinput);
@@ -180,10 +196,9 @@ include_once("kindeditor.php") ;
preview.find("#soutput").html(soutput);
let hint=$("textarea").eq(9).val();
preview.find("#hint").html(hint);
preview.find("#hint .md").each(function(){
$(this).html(marked.parse($(this).html()));
});
if($("#previewFrame")[0] != undefined) $("#previewFrame")[0].contentWindow.MathJax.typeset();
renderPreviewMarkdown($("#previewFrame")[0] != undefined ? $("#previewFrame")[0].contentWindow : null).catch(function (error) {
console.error('Failed to render preview markdown.', error);
});
}
$(document).ready(function(){
// 默认开启预览功能