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

@@ -1,48 +1,25 @@
<meta charset="utf-8" />
<link rel="stylesheet" href="../kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="../kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="../kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="../kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="../kindeditor/plugins/code/prettify.js"></script>
<script src="../include/vditor-adapter.js"></script>
<script>
$(document).ready(window.setTimeout(function (){
KindEditor.ready(function(K) {
let editor1 = K.create('textarea[class="kindeditor"]', {
width : '100%',
cssPath : '../kindeditor/plugins/code/prettify.css',
uploadJson : '../kindeditor/php/upload_json.php',
fileManagerJson : '../kindeditor/php/file_manager_json.php',
allowFileManager : false,
filterMode:false,
cssData: 'body { font-family:"Consolas";font-size: 18px;line-height:150% } ',
// <?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN)
// echo "designMode:false,";
// ?>
afterCreate : function() {
var self = this;
K.ctrl(document, 13, function() {
self.sync();
});
K.ctrl(self.edit.doc, 13, function() {
self.sync();
});
$(document).ready(function () {
HustOJVditor.initTextareaVditors({
selector: 'textarea.kindeditor',
uploadUrl: '../kindeditor/php/upload_json.php',
accept: '*/*',
mode: 'sv',
preview: {
mode: 'both',
delay: 0,
actions: [],
markdown: {
sanitize: false,
autoSpace: false,
fixTermTypo: false
}
,
afterBlur: function() {
var self = this;
self.sync();
}
,
afterChange: function() {
var self = this;
self.sync();
if( typeof sync === "function") sync();
}
});
// prettyPrint();
}
}).catch(function (error) {
console.error('Failed to initialize Vditor.', error);
});
}),100);
});
</script>

View File

@@ -113,8 +113,35 @@ if (!(isset($_SESSION[$OJ_NAME . '_' . 'administrator']) || isset($_SESSION[$OJ_
</form>
</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);
@@ -157,20 +184,11 @@ if (!(isset($_SESSION[$OJ_NAME . '_' . 'administrator']) || isset($_SESSION[$OJ_
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);
@@ -178,10 +196,9 @@ if (!(isset($_SESSION[$OJ_NAME . '_' . 'administrator']) || isset($_SESSION[$OJ_
preview.find("#soutput").html(soutput);
let hint = $("textarea").eq(11).val();
preview.find("#hint").html(hint);
preview.find("#hint .md").each(function () {
$(this).html(marked.parse($(this).html()));
renderPreviewMarkdown($("#previewFrame")[0] != undefined ? $("#previewFrame")[0].contentWindow : null).catch(function (error) {
console.error('Failed to render preview markdown.', error);
});
if ($("#previewFrame")[0] != undefined) $("#previewFrame")[0].contentWindow.MathJax.typeset();
}
$(document).ready(function () {

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(){
// 默认开启预览功能