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

View File

@@ -113,8 +113,35 @@ if (!(isset($_SESSION[$OJ_NAME . '_' . 'administrator']) || isset($_SESSION[$OJ_
</form> </form>
</div> </div>
<script src="<?php echo $OJ_CDN_URL . "/template/bs3/" ?>marked.min.js"></script>
<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() { function transform() {
let height = document.body.clientHeight; let height = document.body.clientHeight;
let width = parseInt(document.body.clientWidth * 0.6); 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(); let description = $("textarea").eq(1).val();
preview.find("#description").html(description); preview.find("#description").html(description);
preview.find("#description .md").each(function () {
$(this).html(marked.parse($(this).html()));
});
let input = $("textarea").eq(3).val(); let input = $("textarea").eq(3).val();
preview.find("#input").html(input); preview.find("#input").html(input);
preview.find("#input .md").each(function () {
$(this).html(marked.parse($(this).html()));
});
let output = $("textarea").eq(5).val(); let output = $("textarea").eq(5).val();
preview.find("#output").html(output); preview.find("#output").html(output);
preview.find("#output .md").each(function () {
$(this).html(marked.parse($(this).html()));
});
let sinput = $("textarea").eq(6).val(); let sinput = $("textarea").eq(6).val();
preview.find("#sinput").html(sinput); preview.find("#sinput").html(sinput);
@@ -178,10 +196,9 @@ if (!(isset($_SESSION[$OJ_NAME . '_' . 'administrator']) || isset($_SESSION[$OJ_
preview.find("#soutput").html(soutput); preview.find("#soutput").html(soutput);
let hint = $("textarea").eq(11).val(); let hint = $("textarea").eq(11).val();
preview.find("#hint").html(hint); preview.find("#hint").html(hint);
preview.find("#hint .md").each(function () { renderPreviewMarkdown($("#previewFrame")[0] != undefined ? $("#previewFrame")[0].contentWindow : null).catch(function (error) {
$(this).html(marked.parse($(this).html())); console.error('Failed to render preview markdown.', error);
}); });
if ($("#previewFrame")[0] != undefined) $("#previewFrame")[0].contentWindow.MathJax.typeset();
} }
$(document).ready(function () { $(document).ready(function () {

View File

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

View File

@@ -19,7 +19,6 @@
<link href="assets/css/lib/bootstrap.min.css" rel="stylesheet"> <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/lib/simdahs.css" rel="stylesheet"> <link href="assets/css/lib/simdahs.css" rel="stylesheet">
<link href="assets/css/style.css" rel="stylesheet"> <link href="assets/css/style.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/wangEditor/10.0.13/wangEditor.js"></script>
<?php <?php
if (!$_SESSION[$OJ_NAME.'_'.'administrator'] && !$_SESSION[$OJ_NAME.'_'.'problem_editor'] && !$_SESSION[$OJ_NAME.'_'.'contest_creator']) { if (!$_SESSION[$OJ_NAME.'_'.'administrator'] && !$_SESSION[$OJ_NAME.'_'.'problem_editor'] && !$_SESSION[$OJ_NAME.'_'.'contest_creator']) {

View File

@@ -1,30 +1,26 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="stylesheet" href="../kindeditor/themes/default/default.css" /> <script src="../include/vditor-adapter.js"></script>
<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> <script>
KindEditor.ready(function(K) { $(document).ready(function () {
var editor1 = K.create('textarea[class="kindeditor"]', { HustOJVditor.initTextareaVditors({
width : '100%', selector: 'textarea.kindeditor',
cssPath : '../kindeditor/plugins/code/prettify.css', uploadUrl: '../kindeditor/php/upload_json.php',
uploadJson : '../kindeditor/php/upload_json.php', accept: '*/*',
fileManagerJson : '../kindeditor/php/file_manager_json.php', mode: 'sv',
allowFileManager : false, ctrlEnterFormName: 'example',
afterCreate : function() { preview: {
var self = this; mode: 'both',
K.ctrl(document, 13, function() { delay: 0,
self.sync(); actions: [],
K('form[name=example]')[0].submit(); markdown: {
}); sanitize: false,
K.ctrl(self.edit.doc, 13, function() { autoSpace: false,
self.sync(); fixTermTypo: false
K('form[name=example]')[0].submit(); }
});
} }
}).catch(function (error) {
console.error('Failed to initialize Vditor.', error);
}); });
// prettyPrint();
}); });
</script> </script>

View File

@@ -85,7 +85,7 @@ static $OJ_RANK_HIDDEN="'admin','super','szx','sen'"; // 管理员不显示在
static $OJ_FRIENDLY_LEVEL=0; //系统友好级别暂定0-9级级别越高越傻瓜系统易用度高的同时将降低安全性仅供非专业用途造成泄题、抄袭概不负责。 static $OJ_FRIENDLY_LEVEL=0; //系统友好级别暂定0-9级级别越高越傻瓜系统易用度高的同时将降低安全性仅供非专业用途造成泄题、抄袭概不负责。
static $OJ_FREE_PRACTICE=true; //自由练习,不受比赛作业用题限制 static $OJ_FREE_PRACTICE=true; //自由练习,不受比赛作业用题限制
static $OJ_SUBMIT_COOLDOWN_TIME=1; //提交冷却时间,连续两次提交的最小间隔,单位秒。 static $OJ_SUBMIT_COOLDOWN_TIME=1; //提交冷却时间,连续两次提交的最小间隔,单位秒。
static $OJ_MARKDOWN='markdown-it'; // 开启MARKDOWN开启后在后台编辑题目时默认为源码模式,用[md] # Markdown [/md] 格式插入markdown代码, 如果需要用到[]也可以用<div class='md'> </div>。 static $OJ_MARKDOWN='vditor'; // 开启 Markdown 渲染,当前统一由 Vditor 处理;后台编辑题目时默认为源码模式,用[md] # Markdown [/md] 格式插入 markdown 代码,如需直接包裹内容也可以用<div class='md'> </div>。
static $OJ_INDEX_NEWS_TITLE='HelloWorld!'; // 在syzoj的首页显示哪一篇标题的文章可以有多个相同标题 static $OJ_INDEX_NEWS_TITLE='HelloWorld!'; // 在syzoj的首页显示哪一篇标题的文章可以有多个相同标题
static $OJ_DIV_FILTER=true; // 过滤题面中的div修复显示异常特别是来自其他OJ系统的题面。 static $OJ_DIV_FILTER=true; // 过滤题面中的div修复显示异常特别是来自其他OJ系统的题面。
static $OJ_LIMIT_TO_1_IP=true; // 限制用户同一时刻只能在一个IP地址登录 static $OJ_LIMIT_TO_1_IP=true; // 限制用户同一时刻只能在一个IP地址登录

View File

@@ -0,0 +1,976 @@
(function (global) {
'use strict';
var documentRef = global.document;
if (!documentRef) {
return;
}
var DEFAULT_CDN = global.HUSTOJ_VDITOR_CDN || 'https://cdn.jsdelivr.net/npm/vditor@3.10.6';
var assetsPromise = null;
var styleInjected = false;
function injectAdapterStyle() {
var style;
if (styleInjected) {
return;
}
style = documentRef.createElement('style');
style.type = 'text/css';
style.setAttribute('data-hustoj-vditor', 'adapter-style');
style.textContent = [
'.hustoj-vditor-hidden{display:none !important;}',
'.hustoj-vditor-wrapper{width:100%;margin:0 0 12px;}',
'.hustoj-vditor-code{--hustoj-vditor-font-size:18px;}',
'.hustoj-vditor-code .vditor-toolbar{display:none !important;}',
'.hustoj-vditor-code .vditor-reset,',
'.hustoj-vditor-code .vditor-content,',
'.hustoj-vditor-code textarea{font-family:Consolas,Monaco,"Courier New",monospace !important;font-size:var(--hustoj-vditor-font-size) !important;line-height:1.5 !important;}',
'.hustoj-vditor-code .vditor-sv,',
'.hustoj-vditor-code .vditor-ir{min-height:100%;}',
'.hustoj-vditor-dark .vditor{background:#272822;border-color:#4a4a4a;}',
'.hustoj-vditor-dark .vditor-reset,',
'.hustoj-vditor-dark .vditor-content,',
'.hustoj-vditor-dark textarea{color:#f8f8f2 !important;background:#272822 !important;}',
'.hustoj-vditor-dark .vditor-toolbar svg{fill:#f8f8f2;}',
'.hustoj-vditor-mail .vditor-toolbar{border-bottom:1px solid #ddd;}',
'.hustoj-vditor-mail .vditor{height:100%;min-height:180px;}'
].join('');
documentRef.head.appendChild(style);
styleInjected = true;
}
function ensureStyleTag(href) {
var existing = documentRef.querySelector('link[data-hustoj-vditor-css="' + href + '"]');
if (existing) {
return;
}
var link = documentRef.createElement('link');
link.rel = 'stylesheet';
link.href = href;
link.setAttribute('data-hustoj-vditor-css', href);
documentRef.head.appendChild(link);
}
function ensureScript(src) {
return new Promise(function (resolve, reject) {
var existing = documentRef.querySelector('script[data-hustoj-vditor-js="' + src + '"]');
if (existing) {
if (global.Vditor) {
resolve(global.Vditor);
} else {
existing.addEventListener('load', function () {
resolve(global.Vditor);
}, { once: true });
existing.addEventListener('error', reject, { once: true });
}
return;
}
var script = documentRef.createElement('script');
script.src = src;
script.async = true;
script.setAttribute('data-hustoj-vditor-js', src);
script.onload = function () {
resolve(global.Vditor);
};
script.onerror = function () {
reject(new Error('Failed to load ' + src));
};
documentRef.head.appendChild(script);
});
}
function ensureAssets(options) {
var cdn = (options && options.cdn) || DEFAULT_CDN;
if (global.Vditor) {
injectAdapterStyle();
return Promise.resolve(global.Vditor);
}
if (assetsPromise) {
return assetsPromise;
}
ensureStyleTag(cdn + '/dist/index.css');
injectAdapterStyle();
assetsPromise = ensureScript(cdn + '/dist/index.min.js').then(function () {
return global.Vditor;
});
return assetsPromise;
}
function resolveElement(target) {
if (!target) {
return null;
}
if (typeof target === 'string') {
return documentRef.getElementById(target) || documentRef.querySelector(target);
}
return target;
}
function getElementValue(element) {
if (!element) {
return '';
}
if (typeof element.value === 'string') {
return element.value;
}
return element.textContent || '';
}
function computeHeight(element, fallbackHeight) {
var computed;
var rows;
var height;
if (element && global.getComputedStyle) {
computed = global.getComputedStyle(element);
height = parseInt(computed.height, 10);
if (!height) {
height = parseInt(computed.minHeight, 10);
}
}
if (!height && element) {
rows = parseInt(element.getAttribute('rows'), 10);
if (rows) {
height = Math.max(rows * 24, fallbackHeight || 320);
}
}
return height || fallbackHeight || 360;
}
function aceThemeToVditorTheme(themeName) {
if (!themeName) {
return 'classic';
}
if (themeName.indexOf('monokai') !== -1 || themeName.indexOf('dark') !== -1) {
return 'dark';
}
return 'classic';
}
function aceThemeToContentTheme(themeName) {
return aceThemeToVditorTheme(themeName) === 'dark' ? 'dark' : 'light';
}
function normalizeMode(modeName) {
if (!modeName) {
return '';
}
return String(modeName).replace(/^ace\/mode\//, '');
}
function dispatchNativeEvent(element, eventName) {
var eventObject;
if (!element || typeof Event === 'undefined') {
return;
}
eventObject = new Event(eventName, { bubbles: true });
element.dispatchEvent(eventObject);
}
function syncFieldValue(field, value, onChange) {
if (!field) {
if (typeof onChange === 'function') {
onChange(value, null);
}
if (typeof global.sync === 'function') {
global.sync();
}
return;
}
field.value = value;
dispatchNativeEvent(field, 'input');
dispatchNativeEvent(field, 'change');
if (typeof onChange === 'function') {
onChange(value, field);
}
if (typeof global.sync === 'function') {
global.sync();
}
}
function decodeHtmlEntities(text) {
var textarea = documentRef.createElement('textarea');
textarea.innerHTML = typeof text === 'string' ? text : '';
return textarea.value;
}
function toElementArray(target) {
var resolved;
if (!target) {
return [];
}
if (typeof target === 'string') {
return Array.prototype.slice.call(documentRef.querySelectorAll(target));
}
if (target.nodeType === 1) {
return [target];
}
if (typeof target.length === 'number') {
return Array.prototype.slice.call(target).map(function (item) {
return resolveElement(item);
}).filter(function (item) {
return !!item;
});
}
resolved = resolveElement(target);
return resolved ? [resolved] : [];
}
function mergeObjects(target, source) {
var key;
if (!source) {
return target;
}
for (key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
return target;
}
function getMarkdownSource(element, options) {
var rawSource;
var source;
if (!element) {
return '';
}
if (!options.refreshSource && typeof element._hustojVditorSource === 'string') {
return element._hustojVditorSource;
}
if (typeof options.getSource === 'function') {
rawSource = options.getSource(element);
} else if (options.useTextContent) {
rawSource = element.textContent || '';
} else {
rawSource = element.innerHTML || '';
}
source = String(rawSource || '');
if (options.decodeEntities !== false) {
source = decodeHtmlEntities(source);
}
element._hustojVditorSource = source;
return source;
}
function buildPreviewOptions(options, afterRender) {
var previewOptions = {
cdn: options.cdn || DEFAULT_CDN,
mode: options.mode || 'light',
anchor: typeof options.anchor === 'undefined' ? 0 : options.anchor,
speech: {
enable: false
},
hljs: {
style: options.codeTheme || 'github'
},
markdown: {
autoSpace: false,
fixTermTypo: false,
toc: false,
codeBlockPreview: true,
mathBlockPreview: true,
sanitize: false
},
math: {
inlineDigit: true
},
after: afterRender
};
if (options.previewOptions) {
mergeObjects(previewOptions, options.previewOptions);
if (options.previewOptions.speech) {
previewOptions.speech = mergeObjects(previewOptions.speech, options.previewOptions.speech);
}
if (options.previewOptions.hljs) {
previewOptions.hljs = mergeObjects(previewOptions.hljs, options.previewOptions.hljs);
}
if (options.previewOptions.markdown) {
previewOptions.markdown = mergeObjects(previewOptions.markdown, options.previewOptions.markdown);
}
if (options.previewOptions.math) {
previewOptions.math = mergeObjects(previewOptions.math, options.previewOptions.math);
}
}
previewOptions.after = afterRender;
return previewOptions;
}
function renderMarkdownBlocks(target, options) {
var renderOptions = options || {};
return ensureAssets(renderOptions).then(function () {
var elements = toElementArray(target);
var tasks = [];
elements.forEach(function (element) {
var source = getMarkdownSource(element, renderOptions);
if (!source && !renderOptions.renderEmpty) {
return;
}
tasks.push(new Promise(function (resolve, reject) {
var previewOptions = buildPreviewOptions(renderOptions, function () {
if (typeof renderOptions.afterEach === 'function') {
renderOptions.afterEach(element, source);
}
resolve(element);
});
try {
global.Vditor.preview(element, source, previewOptions);
} catch (error) {
reject(error);
}
}));
});
return Promise.all(tasks).then(function (result) {
if (typeof renderOptions.afterAll === 'function') {
renderOptions.afterAll(result);
}
return result;
});
});
}
function kindEditorUploadFormatter(files, responseText) {
var payload;
var fileName = 'upload';
var result;
try {
payload = JSON.parse(responseText);
} catch (error) {
return JSON.stringify({
msg: '上传返回解析失败',
code: 1,
data: { errFiles: [fileName], succMap: {} }
});
}
if (files && files.length > 0 && files[0] && files[0].name) {
fileName = files[0].name;
}
if (typeof payload.code !== 'undefined' && payload.data) {
return responseText;
}
if (payload.error === 0 && payload.url) {
result = {
msg: '',
code: 0,
data: {
errFiles: [],
succMap: {}
}
};
result.data.succMap[fileName] = payload.url;
return JSON.stringify(result);
}
return JSON.stringify({
msg: payload.message || payload.msg || '上传失败',
code: 1,
data: {
errFiles: [fileName],
succMap: {}
}
});
}
function buildUploadOptions(options) {
if (!options || !options.uploadUrl) {
return undefined;
}
return {
url: options.uploadUrl,
max: options.uploadMax || 400 * 1024 * 1024,
multiple: false,
fieldName: options.fieldName || 'imgFile',
accept: options.accept || '*/*',
format: function (files, responseText) {
return kindEditorUploadFormatter(files, responseText);
}
};
}
function getDefaultMarkdownToolbar() {
return [
'emoji',
'headings',
'bold',
'italic',
'strike',
'|',
'line',
'quote',
'list',
'ordered-list',
'check',
'|',
'link',
'upload',
'table',
'code',
'inline-code',
'|',
'undo',
'redo',
'|',
'edit-mode',
'both',
'preview',
'fullscreen',
'outline'
];
}
function getDefaultMailToolbar() {
return [
'emoji',
'headings',
'bold',
'italic',
'strike',
'|',
'link',
'upload',
'code',
'inline-code',
'|',
'undo',
'redo',
'|',
'fullscreen'
];
}
function createTextareaEditor(textarea, options) {
var wrapper = documentRef.createElement('div');
var height = computeHeight(textarea, options.height || 360);
var vditor;
wrapper.className = 'hustoj-vditor-wrapper hustoj-vditor-markdown';
textarea.classList.add('hustoj-vditor-hidden');
textarea.parentNode.insertBefore(wrapper, textarea.nextSibling);
return new Promise(function (resolve) {
vditor = new global.Vditor(wrapper, {
cdn: options.cdn || DEFAULT_CDN,
cache: { enable: false },
mode: options.mode || 'sv',
value: textarea.value || '',
lang: options.lang || 'zh_CN',
theme: options.theme || 'classic',
icon: options.icon || 'ant',
width: options.width || '100%',
minHeight: options.minHeight || Math.min(height, 320),
height: options.height || height,
toolbar: options.toolbar || getDefaultMarkdownToolbar(),
toolbarConfig: options.toolbarConfig || { pin: true },
resize: options.resize || { enable: true, position: 'bottom' },
outline: options.outline || { enable: false },
preview: options.preview || {
mode: 'both',
delay: 0,
actions: [],
markdown: {
sanitize: false,
autoSpace: false,
codeBlockPreview: true,
mathBlockPreview: true,
fixTermTypo: false
}
},
upload: buildUploadOptions(options),
ctrlEnter: function (value) {
var form;
syncFieldValue(textarea, value, options.onChange);
if (!options.ctrlEnterFormName) {
return;
}
form = documentRef.querySelector('form[name="' + options.ctrlEnterFormName + '"]');
if (form) {
form.submit();
}
},
input: function (value) {
syncFieldValue(textarea, value, options.onChange);
},
blur: function (value) {
syncFieldValue(textarea, value, options.onChange);
},
after: function () {
syncFieldValue(textarea, vditor.getValue(), options.onChange);
resolve(vditor);
}
});
});
}
function createCodeEditor(options) {
return ensureAssets(options).then(function () {
var container = resolveElement(options.container);
var hiddenField = resolveElement(options.hiddenField);
var sourceField = resolveElement(options.sourceField);
var initialValue = options.initialValue;
var adapter = null;
var vditor = null;
var session = null;
var state;
if (!container) {
throw new Error('Vditor code editor container not found');
}
if (typeof initialValue === 'undefined') {
initialValue = getElementValue(sourceField || container);
}
state = {
theme: options.theme || 'ace/theme/chrome',
fontSize: parseInt(options.fontSize, 10) || 18,
mode: normalizeMode(options.mode || ''),
wrap: true
};
container.classList.add('hustoj-vditor-code');
container.style.setProperty('--hustoj-vditor-font-size', state.fontSize + 'px');
container.classList.toggle('hustoj-vditor-dark', aceThemeToVditorTheme(state.theme) === 'dark');
if (sourceField && sourceField !== container) {
sourceField.classList.add('hustoj-vditor-hidden');
}
container.textContent = '';
function applyTheme() {
var editorTheme = aceThemeToVditorTheme(state.theme);
var contentTheme = aceThemeToContentTheme(state.theme);
container.classList.toggle('hustoj-vditor-dark', editorTheme === 'dark');
if (vditor && typeof vditor.setTheme === 'function') {
vditor.setTheme(editorTheme, contentTheme, 'github');
}
}
function applyFontSize() {
container.style.setProperty('--hustoj-vditor-font-size', state.fontSize + 'px');
}
function syncSourceValue(value) {
if (sourceField && sourceField !== container && typeof sourceField.value === 'string') {
sourceField.value = value;
}
if (hiddenField && typeof hiddenField.value === 'string') {
hiddenField.value = value;
}
if (typeof options.onChange === 'function') {
options.onChange(value);
}
}
session = {
setMode: function (modeName) {
state.mode = normalizeMode(modeName);
},
getValue: function () {
return adapter.getValue();
},
setValue: function (value) {
adapter.setValue(value);
}
};
return new Promise(function (resolve) {
vditor = new global.Vditor(container, {
cdn: options.cdn || DEFAULT_CDN,
cache: { enable: false },
mode: options.editorMode || 'sv',
lang: options.lang || 'zh_CN',
value: initialValue || '',
icon: options.icon || 'ant',
theme: aceThemeToVditorTheme(state.theme),
width: options.width || '100%',
minHeight: options.minHeight || computeHeight(container, 420),
height: options.height || computeHeight(container, 420),
toolbar: options.toolbar || [],
toolbarConfig: options.toolbarConfig || { hide: true, pin: false },
resize: options.resize || { enable: false },
outline: options.outline || { enable: false },
counter: options.counter || { enable: false },
preview: options.preview || {
mode: 'editor',
delay: 0,
actions: [],
markdown: {
sanitize: false,
autoSpace: false,
codeBlockPreview: false,
mathBlockPreview: false,
fixTermTypo: false
}
},
input: function (value) {
syncSourceValue(value);
},
blur: function (value) {
syncSourceValue(value);
},
after: function () {
adapter = {
getValue: function () {
return vditor.getValue();
},
setValue: function (value) {
var nextValue = typeof value === 'undefined' ? '' : String(value);
vditor.setValue(nextValue, true);
syncSourceValue(nextValue);
return nextValue;
},
getSession: function () {
return session;
},
session: session,
setTheme: function (themeName) {
state.theme = themeName || state.theme;
applyTheme();
},
getTheme: function () {
return state.theme;
},
setOptions: function (editorOptions) {
if (!editorOptions) {
return;
}
if (editorOptions.fontSize) {
this.setFontSize(editorOptions.fontSize);
}
if (typeof editorOptions.readOnly !== 'undefined') {
this.setReadOnly(editorOptions.readOnly);
}
},
setOption: function (name, value) {
if (name === 'wrap') {
state.wrap = value !== 'off';
}
},
resize: function () {
applyFontSize();
},
getFontSize: function () {
return String(state.fontSize);
},
setFontSize: function (fontSize) {
state.fontSize = parseInt(fontSize, 10) || state.fontSize;
applyFontSize();
},
setReadOnly: function (readOnly) {
if (readOnly) {
vditor.disabled();
} else {
vditor.enable();
}
},
focus: function () {
vditor.focus();
},
_vditor: vditor
};
applyTheme();
applyFontSize();
if (options.readOnly) {
adapter.setReadOnly(true);
}
syncSourceValue(vditor.getValue());
resolve(adapter);
}
});
});
});
}
function createDeferredCodeEditor(options) {
var initialElement = resolveElement(options && (options.sourceField || options.container));
var proxy = {
_impl: null,
_theme: (options && options.theme) || 'ace/theme/chrome',
_fontSize: parseInt(options && options.fontSize, 10) || 18,
_value: typeof options !== 'undefined' && typeof options.initialValue !== 'undefined' ? options.initialValue : getElementValue(initialElement),
_mode: normalizeMode(options && options.mode),
_options: null,
_readOnly: typeof options !== 'undefined' ? options.readOnly : undefined,
_wrap: 'free'
};
function getProxySession() {
return {
setMode: function (modeName) {
proxy._mode = normalizeMode(modeName);
if (proxy._impl) {
proxy._impl.getSession().setMode(modeName);
}
},
getValue: function () {
return proxy.getValue();
},
setValue: function (value) {
proxy.setValue(value);
}
};
}
proxy.getValue = function () {
if (proxy._impl) {
return proxy._impl.getValue();
}
if (typeof proxy._value !== 'undefined' && proxy._value !== null && proxy._value !== '') {
return proxy._value;
}
return getElementValue(resolveElement(options && (options.sourceField || options.container)));
};
proxy.setValue = function (value) {
proxy._value = value;
if (proxy._impl) {
return proxy._impl.setValue(value);
}
return value;
};
proxy.getSession = function () {
return getProxySession();
};
proxy.session = getProxySession();
proxy.setTheme = function (themeName) {
proxy._theme = themeName || proxy._theme;
if (proxy._impl) {
proxy._impl.setTheme(proxy._theme);
}
};
proxy.getTheme = function () {
if (proxy._impl) {
return proxy._impl.getTheme();
}
return proxy._theme;
};
proxy.setOptions = function (editorOptions) {
proxy._options = editorOptions;
if (editorOptions && editorOptions.fontSize) {
proxy._fontSize = parseInt(editorOptions.fontSize, 10) || proxy._fontSize;
}
if (proxy._impl) {
proxy._impl.setOptions(editorOptions);
}
};
proxy.setOption = function (name, value) {
if (name === 'wrap') {
proxy._wrap = value;
}
if (proxy._impl) {
proxy._impl.setOption(name, value);
}
};
proxy.resize = function () {
if (proxy._impl) {
proxy._impl.resize();
}
};
proxy.getFontSize = function () {
if (proxy._impl) {
return proxy._impl.getFontSize();
}
return String(proxy._fontSize);
};
proxy.setFontSize = function (fontSize) {
proxy._fontSize = parseInt(fontSize, 10) || proxy._fontSize;
if (proxy._impl) {
proxy._impl.setFontSize(proxy._fontSize);
}
};
proxy.setReadOnly = function (readOnly) {
proxy._readOnly = readOnly;
if (proxy._impl) {
proxy._impl.setReadOnly(readOnly);
}
};
proxy.focus = function () {
if (proxy._impl) {
proxy._impl.focus();
}
};
createCodeEditor(options || {}).then(function (instance) {
proxy._impl = instance;
instance.setTheme(proxy._theme);
instance.setFontSize(proxy._fontSize);
if (proxy._options) {
instance.setOptions(proxy._options);
}
if (proxy._mode) {
instance.getSession().setMode('ace/mode/' + proxy._mode);
}
if (typeof proxy._readOnly !== 'undefined') {
instance.setReadOnly(proxy._readOnly);
}
instance.setOption('wrap', proxy._wrap);
if (typeof proxy._value !== 'undefined' && proxy._value !== null) {
instance.setValue(proxy._value);
}
}).catch(function (error) {
console.error('Failed to initialize deferred Vditor code editor.', error);
});
return proxy;
}
function createRichTextEditor(options) {
return ensureAssets(options).then(function () {
var container = resolveElement(options.container);
var hiddenField = resolveElement(options.hiddenField);
var initialValue = options.initialValue || '';
var vditor = null;
var adapter = null;
if (!container) {
throw new Error('Vditor rich editor container not found');
}
container.classList.add('hustoj-vditor-mail');
container.textContent = '';
function syncHtml() {
var html = vditor.getHTML();
if (hiddenField && typeof hiddenField.value === 'string') {
hiddenField.value = html;
}
if (typeof options.onChange === 'function') {
options.onChange(html);
}
}
return new Promise(function (resolve) {
vditor = new global.Vditor(container, {
cdn: options.cdn || DEFAULT_CDN,
cache: { enable: false },
mode: options.mode || 'wysiwyg',
lang: options.lang || 'zh_CN',
value: initialValue,
theme: options.theme || 'classic',
icon: options.icon || 'ant',
width: options.width || '100%',
minHeight: options.minHeight || computeHeight(container, 200),
height: options.height || computeHeight(container, 200),
toolbar: options.toolbar || getDefaultMailToolbar(),
toolbarConfig: options.toolbarConfig || { pin: true },
preview: options.preview || {
mode: 'editor',
delay: 0,
actions: [],
markdown: {
sanitize: false,
autoSpace: false,
fixTermTypo: false
}
},
upload: buildUploadOptions(options),
input: syncHtml,
blur: syncHtml,
after: function () {
adapter = {
getHTML: function () {
return vditor.getHTML();
},
getValue: function () {
return vditor.getValue();
},
setValue: function (value) {
vditor.setValue(value || '', true);
syncHtml();
},
focus: function () {
vditor.focus();
},
txt: {
html: function () {
return vditor.getHTML();
}
},
_vditor: vditor
};
syncHtml();
resolve(adapter);
}
});
});
});
}
function initTextareaVditors(options) {
return ensureAssets(options).then(function () {
var selector = (options && options.selector) || 'textarea.kindeditor';
var textareas = documentRef.querySelectorAll(selector);
var tasks = [];
Array.prototype.forEach.call(textareas, function (textarea) {
tasks.push(createTextareaEditor(textarea, options || {}));
});
return Promise.all(tasks);
});
}
global.HustOJVditor = {
ensureAssets: ensureAssets,
initTextareaVditors: initTextareaVditors,
createCodeEditor: createCodeEditor,
createDeferredCodeEditor: createDeferredCodeEditor,
createRichTextEditor: createRichTextEditor,
renderMarkdownBlocks: renderMarkdownBlocks,
aceThemeToVditorTheme: aceThemeToVditorTheme,
decodeHtmlEntities: decodeHtmlEntities,
kindEditorUploadFormatter: kindEditorUploadFormatter
};
})(window);

View File

@@ -1,30 +1,26 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="stylesheet" href="../kindeditor/themes/default/default.css" /> <script src="../include/vditor-adapter.js"></script>
<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> <script>
KindEditor.ready(function(K) { $(document).ready(function () {
var editor1 = K.create('textarea[class="kindeditor"]', { HustOJVditor.initTextareaVditors({
width : '100%', selector: 'textarea.kindeditor',
cssPath : '../kindeditor/plugins/code/prettify.css', uploadUrl: '../kindeditor/php/upload_json.php',
uploadJson : '../kindeditor/php/upload_json.php', accept: '*/*',
fileManagerJson : '../kindeditor/php/file_manager_json.php', mode: 'sv',
allowFileManager : false, ctrlEnterFormName: 'example',
afterCreate : function() { preview: {
var self = this; mode: 'both',
K.ctrl(document, 13, function() { delay: 0,
self.sync(); actions: [],
K('form[name=example]')[0].submit(); markdown: {
}); sanitize: false,
K.ctrl(self.edit.doc, 13, function() { autoSpace: false,
self.sync(); fixTermTypo: false
K('form[name=example]')[0].submit(); }
});
} }
}).catch(function (error) {
console.error('Failed to initialize Vditor.', error);
}); });
// prettyPrint();
}); });
</script> </script>

View File

@@ -2,7 +2,7 @@
<script src="<?php echo $OJ_CDN_URL.$path_fix."include/"?>jquery-latest.js"></script> <script src="<?php echo $OJ_CDN_URL.$path_fix."include/"?>jquery-latest.js"></script>
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?> <?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/$OJ_TEMPLATE/"?>marked.min.js"></script> <script src="include/vditor-adapter.js"></script>
<?php } ?> <?php } ?>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 --> <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->

File diff suppressed because one or more lines are too long

View File

@@ -246,74 +246,93 @@
} }
} ); } );
} }
function getFrameSourceValue(frameWindow) {
if (frameWindow.editor && typeof frameWindow.editor.getValue === "function") {
return frameWindow.editor.getValue();
}
return frameWindow.$("#source").text();
}
function setFrameSourceValue(frameWindow, value) {
if (frameWindow.editor && typeof frameWindow.editor.setValue === "function") {
frameWindow.editor.setValue(value);
return;
}
frameWindow.$("#source").text(value);
}
function selectOne( num, answer){ function selectOne( num, answer){
let editor = $("iframe")[0].contentWindow.$("#source"); let frameWindow = $("iframe")[0].contentWindow;
let old=editor.text(); let old=getFrameSourceValue(frameWindow);
let key= num+".*"; let key= num+".*";
console.log(key); console.log(key);
let rep=old.replace(new RegExp(key),num+" "+answer); let rep=old.replace(new RegExp(key),num+" "+answer);
editor.text(rep); setFrameSourceValue(frameWindow, rep);
} }
function selectMulti( num, answer){ function selectMulti( num, answer){
let editor = $("iframe")[0].contentWindow.$("#source"); let frameWindow = $("iframe")[0].contentWindow;
let old=editor.text(); let old=getFrameSourceValue(frameWindow);
let key= num+".*"; let key= num+".*";
console.log(key); console.log(key);
let rep=old.replace(new RegExp(key),num+" "+answer); let rep=old.replace(new RegExp(key),num+" "+answer);
editor.text(rep); setFrameSourceValue(frameWindow, rep);
} }
function renderProblemMarkdown() {
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
return HustOJVditor.renderMarkdownBlocks('.md');
<?php } ?>
return Promise.resolve([]);
}
function initializeProblemChoices() {
$('span[class=auto_select]').each(function(){
let i=1;
let start=0;
let raw=$(this).html();
let options=['A','B','C','D'];
while(start>=0){
start=raw.indexOf(i+".",start);
if(start<0) break;
let end=start;
let type="radio"
for(let j=0;j<4;j++){
let option=options[j];
end=raw.indexOf(option+".",start);
if(j==0&&raw.substring(start,end).indexOf("多选")>0) type="checkbox";
if (end<0) break;
let disp="<input type=\""+type+"\" name=\""+i+"\" value=\""+option+"\" />"+option+".";
raw= raw.substring(0,end-1)+disp+raw.substring(end+2);
start+=disp.length;
}
start=end+1;
i++;
}
$(this).html(raw);
});
$('input[type="radio"]').click(function(){
if ($(this).is(':checked'))
{
selectOne($(this).attr("name"),$(this).val());
}
});
$('input[type="checkbox"]').click(function(){
let num=$(this).attr("name");
let answer="";
$("input[type=checkbox][name="+num+"]").each(function(){
if ($(this).is(':checked'))
answer+=$(this).val();
});
selectMulti(num,answer);
});
<?php if ($row['spj']>1 || isset($_GET['sid']) || (isset($OJ_AUTO_SHOW_OFF)&&$OJ_AUTO_SHOW_OFF)){ ?>
transform();
<?php }?>
}
window.renderProblemMarkdown = renderProblemMarkdown;
$( document ).ready( function () { $( document ).ready( function () {
$( "#creator" ).load( "problem-ajax.php?pid=<?php echo $id?>" ); $( "#creator" ).load( "problem-ajax.php?pid=<?php echo $id?>" );
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?> renderProblemMarkdown().catch(function (error) {
$(".md").each(function(){ console.error('Failed to render problem markdown.', error);
$(this).html(marked.parse($(this).html())); }).then(function () {
}); initializeProblemChoices();
<?php } ?> });
//单纯文本1. A. B. C. D. 自动变控件
$('span[class=auto_select]').each(function(){
let i=1;
let start=0;
let raw=$(this).html();
let options=['A','B','C','D'];
while(start>=0){
start=raw.indexOf(i+".",start);
if(start<0) break;
let end=start;
let type="radio"
for(let j=0;j<4;j++){
let option=options[j];
end=raw.indexOf(option+".",start);
if(j==0&&raw.substring(start,end).indexOf("多选")>0) type="checkbox";
if (end<0) break;
let disp="<input type=\""+type+"\" name=\""+i+"\" value=\""+option+"\" />"+option+".";
//console.log(disp);
raw= raw.substring(0,end-1)+disp+raw.substring(end+2);
start+=disp.length;
}
start=end+1;
i++;
}
//console.log(raw);
$(this).html(raw);
});
$('input[type="radio"]').click(function(){
if ($(this).is(':checked'))
{
selectOne($(this).attr("name"),$(this).val());
}
});
$('input[type="checkbox"]').click(function(){
let num=$(this).attr("name");
let answer="";
$("input[type=checkbox][name="+num+"]").each(function(){
if ($(this).is(':checked'))
answer+=$(this).val();
});
selectMulti(num,answer);
});
<?php if ($row['spj']>1 || isset($_GET['sid']) || (isset($OJ_AUTO_SHOW_OFF)&&$OJ_AUTO_SHOW_OFF)){ ?>
transform();
<?php }?>
} ); } );

View File

@@ -39,83 +39,78 @@
<?php include("template/$OJ_TEMPLATE/js.php");?> <?php include("template/$OJ_TEMPLATE/js.php");?>
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?> <?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/bs3/"?>marked.min.js"></script>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
marked.use({ HustOJVditor.renderMarkdownBlocks('#errtxt', {
// 开启异步渲染 getSource: function (element) {
async: true, var pre = element.querySelector ? element.querySelector('pre') : null;
pedantic: false, return pre ? pre.textContent : element.textContent || '';
gfm: true, }
mangle: false, }).then(function () {
headerIds: false for(let i=1;i<10;i++){
}); $(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$("#errtxt").each(function(){ $(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
$(this).html(marked.parse($(this).html())); }
});
// adding note for ```input1 ```output1 in description
for(let i=1;i<10;i++){
$(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
}
$("#errtxt table").addClass("ui mini-table cell striped"); $("#errtxt table").addClass("ui mini-table cell striped");
$("#errtxt table tr:odd td").css({ $("#errtxt table tr:odd td").css({
"border": "1px solid grey", "border": "1px solid grey",
"text-align": "center", "text-align": "center",
"width": "200px", "width": "200px",
"background-color": "#8521d022", "background-color": "#8521d022",
"height": "30px" "height": "30px"
}); });
$("#errtxt table tr:even td").css({ $("#errtxt table tr:even td").css({
"border": "1px solid grey", "border": "1px solid grey",
"text-align": "center", "text-align": "center",
"width": "200px", "width": "200px",
"background-color": "#2185d022", "background-color": "#2185d022",
"height": "30px" "height": "30px"
}); });
$("#errtxt table th").css({ $("#errtxt table th").css({
"border": "1px solid grey", "border": "1px solid grey",
"width": "200px", "width": "200px",
"height": "30px", "height": "30px",
"background-color": "#2185d088", "background-color": "#2185d088",
"text-align": "center" "text-align": "center"
}); });
<?php <?php
if(isset($OJ_DOWNLOAD)&&$OJ_DOWNLOAD){ if(isset($OJ_DOWNLOAD)&&$OJ_DOWNLOAD){
if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){ if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){
?> ?>
let down=$($("#errtxt").find("h2")[0]); let down=$($("#errtxt").find("h2")[0]);
let filename=down.text(); let filename=down.text();
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>"); down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
<?php <?php
}else{ }else{
?> ?>
$("#errtxt").find("h2").each(function(){ $("#errtxt").find("h2").each(function(){
let down=$(this); let down=$(this);
let filename=down.text(); let filename=down.text();
console.log(filename); console.log(filename);
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>"); down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
}); });
<?php <?php
}
} }
}
?> ?>
$("th").each(function(){ $("th").each(function(){
let html=$(this).html(); let html=$(this).html();
html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>"); html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>");
html=html.replace("Yours","<?php echo $MSG_YOURS ?>"); html=html.replace("Yours","<?php echo $MSG_YOURS ?>");
html=html.replace("filename","<?php echo $MSG_FILENAME ?>"); html=html.replace("filename","<?php echo $MSG_FILENAME ?>");
html=html.replace("size","<?php echo $MSG_SIZE ?>"); html=html.replace("size","<?php echo $MSG_SIZE ?>");
html=html.replace("result","<?php echo $MSG_RESULT ?>"); html=html.replace("result","<?php echo $MSG_RESULT ?>");
html=html.replace("memory","<?php echo $MSG_MEMORY?>"); html=html.replace("memory","<?php echo $MSG_MEMORY?>");
html=html.replace("time","<?php echo $MSG_TIME ?>"); html=html.replace("time","<?php echo $MSG_TIME ?>");
$(this).html(html); $(this).html(html);
}); });
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
});
}); });
</script> </script>

View File

@@ -65,30 +65,25 @@
<!-- Placed at the end of the document so the pages load faster --> <!-- Placed at the end of the document so the pages load faster -->
<?php include("template/$OJ_TEMPLATE/js.php");?> <?php include("template/$OJ_TEMPLATE/js.php");?>
<script src="<?php echo $OJ_CDN_URL?>ace/ace.js"></script> <script src="include/vditor-adapter.js"></script>
<script src="<?php echo $OJ_CDN_URL?>ace/ext-language_tools.js"></script>
<script> <script>
$("#language").on("change",changeLanguage); $("#language").on("change",changeLanguage);
//初始化对象 editor = HustOJVditor.createDeferredCodeEditor({
editor = ace.edit("code"); container: "code",
sourceField: "source",
readOnly: <?php echo $readOnly ?>,
theme: "ace/theme/clouds",
fontSize: 18
});
//设置风格和语言更多风格和语言请到github上相应目录查看
theme = "clouds" theme = "clouds"
language = "c_cpp" language = "c_cpp"
editor.setTheme("ace/theme/" + theme); editor.setTheme("ace/theme/" + theme);
editor.session.setMode("ace/mode/" + language); editor.session.setMode("ace/mode/" + language);
//字体大小
editor.setFontSize(18); editor.setFontSize(18);
//设置只读true时只读用于展示代码
editor.setReadOnly(<?php echo $readOnly ?>); editor.setReadOnly(<?php echo $readOnly ?>);
//自动换行,设置为off关闭
editor.setOption("wrap", "free") editor.setOption("wrap", "free")
//启用提示菜单
ace.require("ace/ext/language_tools");
editor.setOptions({ editor.setOptions({
enableBasicAutocompletion: true, enableBasicAutocompletion: true,
enableSnippets: true, enableSnippets: true,

View File

@@ -389,20 +389,20 @@ function resume(){
<script language="Javascript" type="text/javascript" src="<?php echo $OJ_CDN_URL?>include/base64.js"></script> <script language="Javascript" type="text/javascript" src="<?php echo $OJ_CDN_URL?>include/base64.js"></script>
<?php if($OJ_ACE_EDITOR){ ?> <?php if($OJ_ACE_EDITOR){ ?>
<script src="<?php echo $OJ_CDN_URL?>ace/ace.js"></script> <script src="include/vditor-adapter.js"></script>
<script src="<?php echo $OJ_CDN_URL?>ace/ext-language_tools.js"></script>
<script> <script>
ace.require("<?php echo $OJ_CDN_URL?>ace/ext/language_tools"); var editor = HustOJVditor.createDeferredCodeEditor({
var editor = ace.edit("source"); container: "source",
editor.setTheme("ace/theme/chrome"); hiddenField: "hide_source",
theme: "ace/theme/chrome",
fontSize: 20
});
switchLang(<?php echo isset($lastlang)?$lastlang:0 ; ?>); switchLang(<?php echo isset($lastlang)?$lastlang:0 ; ?>);
editor.setOptions({ editor.setOptions({
enableBasicAutocompletion: true, enableBasicAutocompletion: true,
enableSnippets: true, enableSnippets: true,
enableLiveAutocompletion: false, enableLiveAutocompletion: false,
//fontFamily: "Consolas",
fontSize: "20px" fontSize: "20px"
}); });
</script> </script>

View File

@@ -7,11 +7,8 @@
$("#csrf").load("<?php echo $path_fix ?>csrf.php"); $("#csrf").load("<?php echo $path_fix ?>csrf.php");
</script> </script>
<!-- WangEditor编辑器文件-->
<script src="./template/bshark/wangEditor/wangEditor.min.js"></script>
<?php if (isset($OJ_MARKDOWN) && $OJ_MARKDOWN) { ?> <?php if (isset($OJ_MARKDOWN) && $OJ_MARKDOWN) { ?>
<script src="<?php echo $OJ_CDN_URL . $path_fix . "template/$OJ_TEMPLATE/" ?>marked.min.js"></script> <script src="include/vditor-adapter.js"></script>
<?php } ?> <?php } ?>
<!-- 主题核心js --> <!-- 主题核心js -->

View File

@@ -208,26 +208,40 @@ a:hover {
</div> </div>
<?php require("./template/bshark/footer.php");?> <?php require("./template/bshark/footer.php");?>
<?php require("./template/bshark/footer-files.php");?> <?php require("./template/bshark/footer-files.php");?>
<script src="include/vditor-adapter.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var E = window.wangEditor var editor = {
var editor = new E('#editor') txt: {
html: function () {
return $("#aa").val();
}
}
};
editor.customConfig.zIndex = 0 HustOJVditor.createRichTextEditor({
editor.customConfig.menus = [ container: '#editor',
//'head', hiddenField: '#aa',
'bold', mode: 'wysiwyg',
//'italic', minHeight: 180,
//'underline', toolbar: [
'link', 'bold',
//'list', 'italic',
//'quote', 'strike',
//'table', '|',
'image', 'link',
'emoticon', 'emoji',
'code' 'code',
] '|',
// 或者 var editor = new E( document.getElementById('editor') ) 'undo',
editor.create() 'redo',
'|',
'fullscreen'
]
}).then(function (instance) {
editor = instance;
}).catch(function (error) {
console.error('Failed to initialize Vditor mail editor.', error);
});
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
var div = document.getElementById('infos'); var div = document.getElementById('infos');

File diff suppressed because one or more lines are too long

View File

@@ -212,12 +212,19 @@
}); });
} }
function renderProblemMarkdown() {
<?php if (isset($OJ_MARKDOWN) && $OJ_MARKDOWN) { ?>
return HustOJVditor.renderMarkdownBlocks('div.md');
<?php } ?>
return Promise.resolve([]);
}
window.renderProblemMarkdown = renderProblemMarkdown;
$(document).ready(function () { $(document).ready(function () {
<?php if (isset($OJ_MARKDOWN) && $OJ_MARKDOWN) { ?> renderProblemMarkdown().catch(function (error) {
$("div.md").each(function () { console.error('Failed to render problem markdown.', error);
$(this).html(marked.parse($(this).html())); });
});
<?php } ?>
}); });

View File

@@ -59,83 +59,79 @@
explain(); explain();
</script> </script>
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?> <?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/bs3/"?>marked.min.js"></script> <script src="include/vditor-adapter.js"></script>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
marked.use({ HustOJVditor.renderMarkdownBlocks('#errtxt', {
// 开启异步渲染 getSource: function (element) {
async: true, var pre = element.querySelector ? element.querySelector('pre') : null;
pedantic: false, return pre ? pre.textContent : element.textContent || '';
gfm: true, }
mangle: false, }).then(function () {
headerIds: false for(let i=1;i<10;i++){
$(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
}
$("#errtxt table").addClass("ui mini-table cell striped");
$("#errtxt table tr:odd td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"background-color": "#8521d022",
"height": "30px"
});
$("#errtxt table tr:even td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"background-color": "#2185d022",
"height": "30px"
});
$("#errtxt table th").css({
"border": "1px solid grey",
"width": "200px",
"height": "30px",
"background-color": "#2185d088",
"text-align": "center"
});
<?php
if(isset($OJ_DOWNLOAD)&&$OJ_DOWNLOAD){
if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){
?>
let down=$($("#errtxt").find("h2")[0]);
let filename=down.text();
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
<?php
}else{
?>
$("#errtxt").find("h2").each(function(){
let down=$(this);
let filename=down.text();
console.log(filename);
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
});
<?php
}
}
?>
$("th").each(function(){
let html=$(this).html();
html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>");
html=html.replace("Yours","<?php echo $MSG_YOURS ?>");
html=html.replace("filename","<?php echo $MSG_FILENAME ?>");
html=html.replace("size","<?php echo $MSG_SIZE ?>");
html=html.replace("result","<?php echo $MSG_RESULT ?>");
html=html.replace("memory","<?php echo $MSG_MEMORY?>");
html=html.replace("time","<?php echo $MSG_TIME ?>");
$(this).html(html);
});
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
}); });
$("#errtxt").each(function(){
$(this).html(marked.parse($(this).html()));
});
// adding note for ```input1 ```output1 in description
for(let i=1;i<10;i++){
$(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
}
$("#errtxt table").addClass("ui mini-table cell striped");
$("#errtxt table tr:odd td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"background-color": "#8521d022",
"height": "30px"
});
$("#errtxt table tr:even td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"background-color": "#2185d022",
"height": "30px"
});
$("#errtxt table th").css({
"border": "1px solid grey",
"width": "200px",
"height": "30px",
"background-color": "#2185d088",
"text-align": "center"
});
<?php
if(isset($OJ_DOWNLOAD)&&$OJ_DOWNLOAD){
if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){
?>
let down=$($("#errtxt").find("h2")[0]);
let filename=down.text();
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
<?php
}else{
?>
$("#errtxt").find("h2").each(function(){
let down=$(this);
let filename=down.text();
console.log(filename);
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
});
<?php
}
}
?>
$("th").each(function(){
let html=$(this).html();
html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>");
html=html.replace("Yours","<?php echo $MSG_YOURS ?>");
html=html.replace("filename","<?php echo $MSG_FILENAME ?>");
html=html.replace("size","<?php echo $MSG_SIZE ?>");
html=html.replace("result","<?php echo $MSG_RESULT ?>");
html=html.replace("memory","<?php echo $MSG_MEMORY?>");
html=html.replace("time","<?php echo $MSG_TIME ?>");
$(this).html(html);
});
}); });
</script> </script>

View File

@@ -404,12 +404,14 @@
</script> </script>
<script language="Javascript" type="text/javascript" src="include/base64.js"></script> <script language="Javascript" type="text/javascript" src="include/base64.js"></script>
<?php if ($OJ_ACE_EDITOR) { ?> <?php if ($OJ_ACE_EDITOR) { ?>
<script src="ace/ace.js"></script> <script src="include/vditor-adapter.js"></script>
<script src="ace/ext-language_tools.js"></script>
<script> <script>
ace.require("ace/ext/language_tools"); var editor = HustOJVditor.createDeferredCodeEditor({
var editor = ace.edit("source"); container: "source",
editor.setTheme("ace/theme/chrome"); hiddenField: "hide_source",
theme: "ace/theme/chrome",
fontSize: 20
});
switchLang(<?php echo $lastlang ?>); switchLang(<?php echo $lastlang ?>);
editor.setOptions({ editor.setOptions({
enableBasicAutocompletion: true, enableBasicAutocompletion: true,

View File

@@ -58,25 +58,19 @@
explain(); explain();
</script> </script>
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?> <?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/bs3/"?>marked.min.js"></script> <script src="include/vditor-adapter.js"></script>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
marked.use({ HustOJVditor.renderMarkdownBlocks('#errtxt', {
// 开启异步渲染 getSource: function (element) {
async: true, var pre = element.querySelector ? element.querySelector('pre') : null;
pedantic: false, return pre ? pre.textContent : element.textContent || '';
gfm: true, }
mangle: false, }).then(function () {
headerIds: false for(let i=1;i<10;i++){
}); $(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$("#errtxt").each(function(){ $(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
$(this).html(marked.parse($(this).html())); }
});
// adding note for ```input1 ```output1 in description
for(let i=1;i<10;i++){
$(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
}
$("#errtxt table").addClass("ui mini-table cell striped"); $("#errtxt table").addClass("ui mini-table cell striped");
@@ -112,10 +106,10 @@
}else{ }else{
?> ?>
$("#errtxt").find("h2").each(function(){ $("#errtxt").find("h2").each(function(){
let down=$(this); let down=$(this);
let filename=down.text(); let filename=down.text();
console.log(filename); console.log(filename);
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>"); down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
}); });
<?php <?php
@@ -123,18 +117,20 @@
} }
?> ?>
$("th").each(function(){ $("th").each(function(){
let html=$(this).html(); let html=$(this).html();
html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>"); html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>");
html=html.replace("Yours","<?php echo $MSG_YOURS ?>"); html=html.replace("Yours","<?php echo $MSG_YOURS ?>");
html=html.replace("filename","<?php echo $MSG_FILENAME ?>"); html=html.replace("filename","<?php echo $MSG_FILENAME ?>");
html=html.replace("size","<?php echo $MSG_SIZE ?>"); html=html.replace("size","<?php echo $MSG_SIZE ?>");
html=html.replace("result","<?php echo $MSG_RESULT ?>"); html=html.replace("result","<?php echo $MSG_RESULT ?>");
html=html.replace("memory","<?php echo $MSG_MEMORY?>"); html=html.replace("memory","<?php echo $MSG_MEMORY?>");
html=html.replace("time","<?php echo $MSG_TIME ?>"); html=html.replace("time","<?php echo $MSG_TIME ?>");
$(this).html(html); $(this).html(html);
}); });
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
});
}); });
</script> </script>

View File

@@ -70,30 +70,25 @@
<!-- Placed at the end of the document so the pages load faster --> <!-- Placed at the end of the document so the pages load faster -->
<?php include("template/$OJ_TEMPLATE/js.php");?> <?php include("template/$OJ_TEMPLATE/js.php");?>
<script src="ace/ace.js"></script> <script src="include/vditor-adapter.js"></script>
<script src="ace/ext-language_tools.js"></script>
<script> <script>
$("#language").on("change",changeLanguage); $("#language").on("change",changeLanguage);
//初始化对象 editor = HustOJVditor.createDeferredCodeEditor({
editor = ace.edit("code"); container: "code",
sourceField: "source",
readOnly: <?php echo $readOnly ?>,
theme: "ace/theme/clouds",
fontSize: 18
});
//设置风格和语言更多风格和语言请到github上相应目录查看
theme = "clouds" theme = "clouds"
language = "c_cpp" language = "c_cpp"
editor.setTheme("ace/theme/" + theme); editor.setTheme("ace/theme/" + theme);
editor.session.setMode("ace/mode/" + language); editor.session.setMode("ace/mode/" + language);
//字体大小
editor.setFontSize(18); editor.setFontSize(18);
//设置只读true时只读用于展示代码
editor.setReadOnly(<?php echo $readOnly ?>); editor.setReadOnly(<?php echo $readOnly ?>);
//自动换行,设置为off关闭
editor.setOption("wrap", "free") editor.setOption("wrap", "free")
//启用提示菜单
ace.require("ace/ext/language_tools");
editor.setOptions({ editor.setOptions({
enableBasicAutocompletion: true, enableBasicAutocompletion: true,
enableSnippets: true, enableSnippets: true,

View File

@@ -397,23 +397,14 @@
<script language="Javascript" type="text/javascript" src="include/base64.js"></script> <script language="Javascript" type="text/javascript" src="include/base64.js"></script>
<?php if($OJ_ACE_EDITOR){ ?> <?php if($OJ_ACE_EDITOR){ ?>
<?php if(isset($MDUI_OFFLINE) && $MDUI_OFFLINE) { ?> <script src="include/vditor-adapter.js"></script>
<script src="<?php echo $OJ_CDN_URL.$path_fix."/"; ?>/ace/ace.min.js"></script>
<script src="<?php echo $OJ_CDN_URL.$path_fix."/"; ?>/ace/ext-language_tools.min.js"></script>
<script>
ace.config.set('basePath', '<?php echo $OJ_CDN_URL.$path_fix."template/$OJ_TEMPLATE"; ?>/assets/ace/');
</script>
<?php } else { ?>
<script src="https://cdn.jsdelivr.net/npm/ace-builds@1.4.12/src-noconflict/ace.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ace-builds@1.4.12/src-noconflict/ext-language_tools.min.js"></script>
<script>
ace.config.set('basePath', 'https://cdn.jsdelivr.net/npm/ace-builds@1.4.12/src-min-noconflict/');
</script>
<?php } ?>
<script> <script>
ace.require("ace/ext/language_tools"); var editor = HustOJVditor.createDeferredCodeEditor({
var editor = ace.edit("source"); container: "source",
editor.setTheme("ace/theme/chrome"); hiddenField: "hide_source",
theme: "ace/theme/chrome",
fontSize: 20
});
switchLang(<?php echo isset($lastlang) ? $lastlang : 0 ; ?>); switchLang(<?php echo isset($lastlang) ? $lastlang : 0 ; ?>);
editor.setOptions({ editor.setOptions({
enableBasicAutocompletion: true, enableBasicAutocompletion: true,

View File

@@ -7,7 +7,7 @@
?> ?>
<?php include("template/$OJ_TEMPLATE/header.php");?> <?php include("template/$OJ_TEMPLATE/header.php");?>
<?php include("include/bbcode.php");?> <?php include("include/bbcode.php");?>
<script src="<?php echo "template/bs3/"?>marked.min.js"></script> <script src="include/vditor-adapter.js"></script>
<div class="padding"> <div class="padding">
<h1><?php echo $news_title ?></h1> <h1><?php echo $news_title ?></h1>
<div class="ui existing segment"> <div class="ui existing segment">
@@ -15,37 +15,47 @@
</div> </div>
</div> </div>
<script> <script>
$(document).ready(function(){ function addMarkdownInputOutputLabels() {
marked.use({ for(let i=1;i<10;i++){
// 开启异步渲染 $(".language-input"+i).parent().each(function(){
async: true, if ($(this).prev('.hustoj-md-io-label').length === 0) {
pedantic: false, $(this).before("<div class='hustoj-md-io-label'><?php echo $MSG_Input?>"+i+":</div>");
gfm: true, }
mangle: false, });
headerIds: false $(".language-output"+i).parent().each(function(){
}); if ($(this).prev('.hustoj-md-io-label').length === 0) {
$(".md").each(function(){ $(this).before("<div class='hustoj-md-io-label'><?php echo $MSG_Output?>"+i+":</div>");
$(this).html(marked.parse($(this).text())); }
}); });
// adding note for ```input1 ```output1 in description }
for(let i=1;i<10;i++){ }
$(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
}
$(".md table tr td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"height": "30px"
});
$(".md table th").css({ function styleMarkdownTables() {
"border": "1px solid grey", $(".md table tr td").css({
"width": "200px", "border": "1px solid grey",
"height": "30px", "text-align": "center",
"background-color": "#9e9e9ea1", "width": "200px",
"text-align": "center" "height": "30px"
}); });
$(".md table th").css({
"border": "1px solid grey",
"width": "200px",
"height": "30px",
"background-color": "#9e9e9ea1",
"text-align": "center"
});
}
$(document).ready(function(){
HustOJVditor.renderMarkdownBlocks('.md', {
useTextContent: true
}).then(function () {
addMarkdownInputOutputLabels();
styleMarkdownTables();
}).catch(function (error) {
console.error('Failed to render discuss markdown.', error);
});
}); });
</script> </script>
<?php include("template/$OJ_TEMPLATE/footer.php");?> <?php include("template/$OJ_TEMPLATE/footer.php");?>

File diff suppressed because one or more lines are too long

View File

@@ -33,8 +33,7 @@ div[class*=ace_br] {
} }
</style> </style>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/$OJ_TEMPLATE/"?>clipboard.min.js"></script> <script src="<?php echo $OJ_CDN_URL.$path_fix."template/$OJ_TEMPLATE/"?>clipboard.min.js"></script>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/bs3/"?>marked.min.js"></script> <script src="include/vditor-adapter.js"></script>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/syzoj/js/"?>markdown-it.min.js"></script>
<div class="padding "> <div class="padding ">
<div class="ui center aligned grid"> <div class="ui center aligned grid">
@@ -399,154 +398,172 @@ function phpfm(pid){
} }
}); });
} }
function getFrameSourceValue(frameWindow){
if(frameWindow.editor && typeof frameWindow.editor.getValue === "function"){
return frameWindow.editor.getValue();
}
return frameWindow.$("#source").text();
}
function setFrameSourceValue(frameWindow, value){
if(frameWindow.editor && typeof frameWindow.editor.setValue === "function"){
frameWindow.editor.setValue(value);
return;
}
frameWindow.$("#source").text(value);
}
function selectOne( num, answer){ function selectOne( num, answer){
let editor = $("iframe")[0].contentWindow.$("#source"); let frameWindow = $("iframe")[0].contentWindow;
let old=editor.text(); let old=getFrameSourceValue(frameWindow);
let key= num+".*"; let key= num+".*";
console.log(key); console.log(key);
let rep=old.replace(new RegExp(key),num+" "+answer); let rep=old.replace(new RegExp(key),num+" "+answer);
editor.text(rep); setFrameSourceValue(frameWindow, rep);
} }
function selectMulti( num, answer){ function selectMulti( num, answer){
let editor = $("iframe")[0].contentWindow.$("#source"); let frameWindow = $("iframe")[0].contentWindow;
let old=editor.text(); let old=getFrameSourceValue(frameWindow);
let key= num+".*"; let key= num+".*";
console.log(key); console.log(key);
let rep=old.replace(new RegExp(key),num+" "+answer); let rep=old.replace(new RegExp(key),num+" "+answer);
editor.text(rep); setFrameSourceValue(frameWindow, rep);
} }
$(document).ready(function(){ $(document).ready(function(){
$("#creator").load("problem-ajax.php?pid=<?php echo $id?>"); $("#creator").load("problem-ajax.php?pid=<?php echo $id?>");
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
marked.use({
// 开启异步渲染
async: true,
pedantic: false,
gfm: true,
mangle: false,
headerIds: false
});
$(".md").each(function(){ function addMarkdownInputOutputLabels() {
<?php if ($OJ_MARKDOWN && $OJ_MARKDOWN=="marked.js") {?> for (let i = 1; i < 10; i++) {
$(this).html(marked.parse($(this).html())); $(".language-input" + i).parent().each(function(){
<?php }else if ($OJ_MARKDOWN && $OJ_MARKDOWN=="markdown-it") {?> if ($(this).prev('.hustoj-md-io-label').length === 0) {
const md = window.markdownit(); $(this).before("<div class='hustoj-md-io-label'><?php echo $MSG_Input?>" + i + ":</div>");
$(this).html(md.render($(this).text())); }
<?php } ?>
});
// adding note for ```input1 ```output1 in description
for(let i=1;i<10;i++){
$(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
}
$(".md table tr td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"height": "30px"
}); });
$(".language-output" + i).parent().each(function(){
$(".md table th").css({ if ($(this).prev('.hustoj-md-io-label').length === 0) {
"border": "1px solid grey", $(this).before("<div class='hustoj-md-io-label'><?php echo $MSG_Output?>" + i + ":</div>");
"width": "200px", }
"height": "30px",
"background-color": "#9e9e9ea1",
"text-align": "center"
}); });
}
}
<?php } ?> function styleMarkdownTables() {
//单纯文本1. A. B. C. D. 自动变控件 $(".md table tr td").css({
$('span[class=auto_select]').each(function(){ "border": "1px solid grey",
let i=1; "text-align": "center",
let start=0; "width": "200px",
let next=0; "height": "30px"
let raw=$(this).html(); });
let options=['A','B','C','D'];
console.log("scanning..."); $(".md table th").css({
while(start>=0){ "border": "1px solid grey",
start=raw.indexOf("\n"+i+".",start); "width": "200px",
if(start<0) break; "height": "30px",
let end=start; "background-color": "#9e9e9ea1",
let type="radio" "text-align": "center"
for(let j=0;j<4;j++){ });
let option=options[j]; }
end=raw.indexOf(option+".",start);
next=raw.indexOf("\n"+(i+1)+".",start); function renderProblemMarkdown() {
console.log("["+raw.substring(start,end)+"]"); <?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
if ( end<0 || ( end > next && next > 0 )) { return HustOJVditor.renderMarkdownBlocks('.md').then(function () {
console.log("i:"+i+" j:"+option+" end:"+end+" next:"+next); addMarkdownInputOutputLabels();
end=start; styleMarkdownTables();
break; });
} <?php } ?>
if(j==0&&raw.substring(start,end).indexOf("多选")>0) type="checkbox"; return Promise.resolve([]);
let disp="<input type=\""+type+"\" name=\""+i+"\" value=\""+option+"\" />"+option+"."; }
//console.log(disp);
raw= raw.substring(0,end-1)+disp+raw.substring(end+2); function initializeProblemChoices() {
start+=disp.length; $('span[class=auto_select]').each(function(){
} let i=1;
start=end+1; let start=0;
i++; let next=0;
} let raw=$(this).html();
//console.log(raw); let options=['A','B','C','D'];
$(this).html(raw); console.log("scanning...");
while(start>=0){
start=raw.indexOf("\n"+i+".",start);
if(start<0) break;
let end=start;
let type="radio"
for(let j=0;j<4;j++){
let option=options[j];
end=raw.indexOf(option+".",start);
next=raw.indexOf("\n"+(i+1)+".",start);
console.log("["+raw.substring(start,end)+"]");
if ( end<0 || ( end > next && next > 0 )) {
console.log("i:"+i+" j:"+option+" end:"+end+" next:"+next);
end=start;
break;
}
if(j==0&&raw.substring(start,end).indexOf("多选")>0) type="checkbox";
let disp="<input type=\""+type+"\" name=\""+i+"\" value=\""+option+"\" />"+option+".";
raw= raw.substring(0,end-1)+disp+raw.substring(end+2);
start+=disp.length;
}
start=end+1;
i++;
}
$(this).html(raw);
});
$('span[class="md auto_select"]').each(function(){
let i=1;
let options=['A','B','C','D','E','F','G'];
$(this).find("ul").each(function(){
let type="radio";
let ol=$(this).prev("ol");
if(ol!=undefined && ol.attr("start")!=undefined) i=ol.attr("start");
console.log("id["+i+"]");
if($(this).html().indexOf("多选")>0|| (ol!=undefined && ol.html()!=undefined && ol.html().indexOf("multiselect")>0)) type="checkbox";
let j=0;
$(this).find("li").each(function(){
let option=options[j];
let disp="<input type=\""+type+"\" name=\""+i+"\" value=\""+option+"\" />"+option+".";
$(this).prepend(disp);
j++;
});
i++;
}); });
let html=$(this).html();
for(;i>0;i--){
console.log("searching..."+i);
html=html.replace("{{ input("+i+") }}","<input type='text' size=5 name='"+i+"' placeholder='第"+i+"题' ><br>");
}
html=html.replaceAll("","&lt;");
html=html.replaceAll("","&gt;");
$(this).html(html);
});
// subjective problems from hydroOJ markdown and embeded marks $(".auto_select").find('input[type="text"]').change(function(){
$('span[class="md auto_select"]').each(function(){ selectOne($(this).attr("name"),$(this).val());
let i=1; });
let options=['A','B','C','D','E','F','G'];
$(this).find("ul").each(function(){ $('input[type="radio"]').click(function(){
let type="radio"; if ($(this).is(':checked'))
let ol=$(this).prev("ol"); selectOne($(this).attr("name"),$(this).val());
if(ol!=undefined && ol.attr("start")!=undefined) i=ol.attr("start"); }).css("width","24px").css("height","21px");
console.log("id["+i+"]"); $('input[type="checkbox"]').click(function(){
if($(this).html().indexOf("多选")>0|| (ol!=undefined && ol.html()!=undefined && ol.html().indexOf("multiselect")>0)) type="checkbox"; let num=$(this).attr("name");
let j=0; let answer="";
$(this).find("li").each(function(){ $("input[type=checkbox][name="+num+"]").each(function(){
let option=options[j]; if ($(this).is(':checked'))
let disp="<input type=\""+type+"\" name=\""+i+"\" value=\""+option+"\" />"+option+"."; answer+=$(this).val();
$(this).prepend(disp);
//console.log(options[j]);
j++;
});
i++;
});
let html=$(this).html();
for(;i>0;i--){
console.log("searching..."+i);
html=html.replace("{{ input("+i+") }}","<input type='text' size=5 name='"+i+"' placeholder='第"+i+"题' ><br>");
}
html=html.replaceAll("","&lt;");
html=html.replaceAll("","&gt;");
$(this).html(html);
}); });
selectMulti(num,answer);
}).css("width","24px").css("height","21px");
<?php if ($row['spj']>1 || isset($_GET['sid']) || (isset($OJ_AUTO_SHOW_OFF)&&$OJ_AUTO_SHOW_OFF)){?>
transform();
<?php }?>
}
window.renderProblemMarkdown = renderProblemMarkdown;
$(".auto_select").find('input[type="text"]').change(function(){ renderProblemMarkdown().catch(function (error) {
selectOne($(this).attr("name"),$(this).val()); console.error('Failed to render problem markdown.', error);
}); }).then(function () {
initializeProblemChoices();
});
$('input[type="radio"]').click(function(){
if ($(this).is(':checked'))
selectOne($(this).attr("name"),$(this).val());
}).css("width","24px").css("height","21px");
$('input[type="checkbox"]').click(function(){
let num=$(this).attr("name");
let answer="";
$("input[type=checkbox][name="+num+"]").each(function(){
if ($(this).is(':checked'))
answer+=$(this).val();
});
selectMulti(num,answer);
}).css("width","24px").css("height","21px");
<?php if ($row['spj']>1 || isset($_GET['sid']) || (isset($OJ_AUTO_SHOW_OFF)&&$OJ_AUTO_SHOW_OFF)){?>
transform();
<?php }?>
}); });
</script> </script>

View File

@@ -1,7 +1,7 @@
<?php $show_title=$id." - $MSG_ERROR_INFO - $OJ_NAME"; ?> <?php $show_title=$id." - $MSG_ERROR_INFO - $OJ_NAME"; ?>
<?php include("template/$OJ_TEMPLATE/header.php");?> <?php include("template/$OJ_TEMPLATE/header.php");?>
<script src="<?php echo "template/bs3/"?>marked.min.js"></script> <script src="include/vditor-adapter.js"></script>
<script src="template/<?php echo $OJ_TEMPLATE?>/js/textFit.min.js"></script> <script src="template/<?php echo $OJ_TEMPLATE?>/js/textFit.min.js"></script>
<style> <style>
.single-subtask { .single-subtask {
@@ -92,83 +92,78 @@
</script> </script>
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?> <?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/bs3/"?>marked.min.js"></script>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
marked.use({ HustOJVditor.renderMarkdownBlocks('#errtxt', {
// 开启异步渲染 getSource: function (element) {
async: true, var pre = element.querySelector ? element.querySelector('pre') : null;
pedantic: false, return pre ? pre.textContent : element.textContent || '';
gfm: true, }
mangle: false, }).then(function () {
headerIds: false for(let i=1;i<10;i++){
}); $(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$("#errtxt").each(function(){ $(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
$(this).html(marked.parse($(this).html())); }
});
// adding note for ```input1 ```output1 in description
for(let i=1;i<10;i++){
$(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
}
$("#errtxt table").addClass("ui mini-table cell striped"); $("#errtxt table").addClass("ui mini-table cell striped");
$("#errtxt table tr:odd td").css({ $("#errtxt table tr:odd td").css({
"border": "1px solid grey", "border": "1px solid grey",
"text-align": "center", "text-align": "center",
"width": "200px", "width": "200px",
"background-color": "#8521d022", "background-color": "#8521d022",
"height": "30px" "height": "30px"
}); });
$("#errtxt table tr:even td").css({ $("#errtxt table tr:even td").css({
"border": "1px solid grey", "border": "1px solid grey",
"text-align": "center", "text-align": "center",
"width": "200px", "width": "200px",
"background-color": "#2185d022", "background-color": "#2185d022",
"height": "30px" "height": "30px"
}); });
$("#errtxt table th").css({ $("#errtxt table th").css({
"border": "1px solid grey", "border": "1px solid grey",
"width": "200px", "width": "200px",
"height": "30px", "height": "30px",
"background-color": "#2185d088", "background-color": "#2185d088",
"text-align": "center" "text-align": "center"
}); });
<?php <?php
if(isset($OJ_DOWNLOAD)&&$OJ_DOWNLOAD){ if(isset($OJ_DOWNLOAD)&&$OJ_DOWNLOAD){
if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){ if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){
?> ?>
let down=$($("#errtxt").find("h2")[0]); let down=$($("#errtxt").find("h2")[0]);
let filename=down.text(); let filename=down.text();
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>"); down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
<?php <?php
}else{ }else{
?> ?>
$("#errtxt").find("h2").each(function(){ $("#errtxt").find("h2").each(function(){
let down=$(this); let down=$(this);
let filename=down.text(); let filename=down.text();
console.log(filename); console.log(filename);
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>"); down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
}); });
<?php <?php
} }
} }
?> ?>
$("th").each(function(){ $("th").each(function(){
let html=$(this).html(); let html=$(this).html();
html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>"); html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>");
html=html.replace("Yours","<?php echo $MSG_YOURS ?>"); html=html.replace("Yours","<?php echo $MSG_YOURS ?>");
html=html.replace("filename","<?php echo $MSG_FILENAME ?>"); html=html.replace("filename","<?php echo $MSG_FILENAME ?>");
html=html.replace("size","<?php echo $MSG_SIZE ?>"); html=html.replace("size","<?php echo $MSG_SIZE ?>");
html=html.replace("result","<?php echo $MSG_RESULT ?>"); html=html.replace("result","<?php echo $MSG_RESULT ?>");
html=html.replace("memory","<?php echo $MSG_MEMORY?>"); html=html.replace("memory","<?php echo $MSG_MEMORY?>");
html=html.replace("time","<?php echo $MSG_TIME ?>"); html=html.replace("time","<?php echo $MSG_TIME ?>");
$(this).html(html); $(this).html(html);
});
});
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
});
}); });
</script> </script>

View File

@@ -423,19 +423,19 @@ function loadFromBlockly(){
} }
?> ?>
<?php if($OJ_ACE_EDITOR){ ?> <?php if($OJ_ACE_EDITOR){ ?>
<script src="<?php echo $OJ_CDN_URL?>ace/ace.js"></script> <script src="include/vditor-adapter.js"></script>
<script src="<?php echo $OJ_CDN_URL?>ace/ext-language_tools.js"></script>
<script> <script>
ace.require("ace/ext/language_tools"); var editor = HustOJVditor.createDeferredCodeEditor({
var editor = ace.edit("source"); container: "source",
editor.setTheme("ace/theme/xcode"); hiddenField: "hide_source",
theme: "ace/theme/xcode",
fontSize: 18
});
switchLang(<?php echo $lastlang ?>); switchLang(<?php echo $lastlang ?>);
editor.setOptions({ editor.setOptions({
enableBasicAutocompletion: true, enableBasicAutocompletion: true,
enableSnippets: true, enableSnippets: true,
enableLiveAutocompletion: true, //改为true,打开自动补齐功能改为false关闭 enableLiveAutocompletion: true,
// fontFamily: "Consolas", // MacOS missing align
// theme: "ace/theme/ambiance", // Black theme
fontSize: "18px" fontSize: "18px"
}); });
reloadtemplate($("#language").val()); reloadtemplate($("#language").val());

View File

@@ -77,83 +77,79 @@
</script> </script>
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?> <?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/bs3/"?>marked.min.js"></script> <script src="include/vditor-adapter.js"></script>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
marked.use({ HustOJVditor.renderMarkdownBlocks('#errtxt', {
// 开启异步渲染 getSource: function (element) {
async: true, var pre = element.querySelector ? element.querySelector('pre') : null;
pedantic: false, return pre ? pre.textContent : element.textContent || '';
gfm: true, }
mangle: false, }).then(function () {
headerIds: false for(let i=1;i<10;i++){
}); $(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$("#errtxt").each(function(){ $(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
$(this).html(marked.parse($(this).html())); }
});
// adding note for ```input1 ```output1 in description
for(let i=1;i<10;i++){
$(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
}
$("#errtxt table").addClass("ui mini-table cell striped"); $("#errtxt table").addClass("ui mini-table cell striped");
$("#errtxt table tr:odd td").css({ $("#errtxt table tr:odd td").css({
"border": "1px solid grey", "border": "1px solid grey",
"text-align": "center", "text-align": "center",
"width": "200px", "width": "200px",
"background-color": "#8521d022", "background-color": "#8521d022",
"height": "30px" "height": "30px"
}); });
$("#errtxt table tr:even td").css({ $("#errtxt table tr:even td").css({
"border": "1px solid grey", "border": "1px solid grey",
"text-align": "center", "text-align": "center",
"width": "200px", "width": "200px",
"background-color": "#2185d022", "background-color": "#2185d022",
"height": "30px" "height": "30px"
}); });
$("#errtxt table th").css({ $("#errtxt table th").css({
"border": "1px solid grey", "border": "1px solid grey",
"width": "200px", "width": "200px",
"height": "30px", "height": "30px",
"background-color": "#2185d088", "background-color": "#2185d088",
"text-align": "center" "text-align": "center"
}); });
<?php <?php
if(isset($OJ_DOWNLOAD)&&$OJ_DOWNLOAD){ if(isset($OJ_DOWNLOAD)&&$OJ_DOWNLOAD){
if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){ if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){
?> ?>
let down=$($("#errtxt").find("h2")[0]); let down=$($("#errtxt").find("h2")[0]);
let filename=down.text(); let filename=down.text();
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>"); down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
<?php <?php
}else{ }else{
?> ?>
$("#errtxt").find("h2").each(function(){ $("#errtxt").find("h2").each(function(){
let down=$(this); let down=$(this);
let filename=down.text(); let filename=down.text();
console.log(filename); console.log(filename);
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>"); down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
}); });
<?php <?php
} }
} }
?> ?>
$("th").each(function(){ $("th").each(function(){
let html=$(this).html(); let html=$(this).html();
html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>"); html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>");
html=html.replace("Yours","<?php echo $MSG_YOURS ?>"); html=html.replace("Yours","<?php echo $MSG_YOURS ?>");
html=html.replace("filename","<?php echo $MSG_FILENAME ?>"); html=html.replace("filename","<?php echo $MSG_FILENAME ?>");
html=html.replace("size","<?php echo $MSG_SIZE ?>"); html=html.replace("size","<?php echo $MSG_SIZE ?>");
html=html.replace("result","<?php echo $MSG_RESULT ?>"); html=html.replace("result","<?php echo $MSG_RESULT ?>");
html=html.replace("memory","<?php echo $MSG_MEMORY?>"); html=html.replace("memory","<?php echo $MSG_MEMORY?>");
html=html.replace("time","<?php echo $MSG_TIME ?>"); html=html.replace("time","<?php echo $MSG_TIME ?>");
$(this).html(html); $(this).html(html);
});
});
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
});
}); });
</script> </script>

View File

@@ -328,20 +328,22 @@ function loadFromBlockly(){
</script> </script>
<script language="Javascript" type="text/javascript" src="include/base64.js"></script> <script language="Javascript" type="text/javascript" src="include/base64.js"></script>
<?php if($OJ_ACE_EDITOR){ ?> <?php if($OJ_ACE_EDITOR){ ?>
<script src="ace/ace.js"></script> <script src="include/vditor-adapter.js"></script>
<script src="ace/ext-language_tools.js"></script>
<script> <script>
ace.require("ace/ext/language_tools"); var editor = HustOJVditor.createDeferredCodeEditor({
var editor = ace.edit("source"); container: "source",
editor.setTheme("ace/theme/chrome"); hiddenField: "hide_source",
switchLang(<?php echo $lastlang ?>); theme: "ace/theme/chrome",
editor.setOptions({ fontSize: 20
});
switchLang(<?php echo $lastlang ?>);
editor.setOptions({
enableBasicAutocompletion: true, enableBasicAutocompletion: true,
enableSnippets: true, enableSnippets: true,
enableLiveAutocompletion: false, enableLiveAutocompletion: false,
fontFamily: "Consolas", fontFamily: "Consolas",
fontSize: "20px" fontSize: "20px"
}); });
reloadtemplate($("#language").val()); reloadtemplate($("#language").val());
</script> </script>

View File

@@ -7,7 +7,7 @@
?> ?>
<?php include("template/$OJ_TEMPLATE/header.php");?> <?php include("template/$OJ_TEMPLATE/header.php");?>
<?php include("include/bbcode.php");?> <?php include("include/bbcode.php");?>
<script src="<?php echo "template/bs3/"?>marked.min.js"></script> <script src="include/vditor-adapter.js"></script>
<div class="padding"> <div class="padding">
<h1><?php echo $news_title ?></h1> <h1><?php echo $news_title ?></h1>
<div class="ui existing segment"> <div class="ui existing segment">
@@ -15,37 +15,47 @@
</div> </div>
</div> </div>
<script> <script>
$(document).ready(function(){ function addMarkdownInputOutputLabels() {
marked.use({ for(let i=1;i<10;i++){
// 开启异步渲染 $(".language-input"+i).parent().each(function(){
async: true, if ($(this).prev('.hustoj-md-io-label').length === 0) {
pedantic: false, $(this).before("<div class='hustoj-md-io-label'><?php echo $MSG_Input?>"+i+":</div>");
gfm: true, }
mangle: false, });
headerIds: false $(".language-output"+i).parent().each(function(){
}); if ($(this).prev('.hustoj-md-io-label').length === 0) {
$(".md").each(function(){ $(this).before("<div class='hustoj-md-io-label'><?php echo $MSG_Output?>"+i+":</div>");
$(this).html(marked.parse($(this).text())); }
}); });
// adding note for ```input1 ```output1 in description }
for(let i=1;i<10;i++){ }
$(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
}
$(".md table tr td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"height": "30px"
});
$(".md table th").css({ function styleMarkdownTables() {
"border": "1px solid grey", $(".md table tr td").css({
"width": "200px", "border": "1px solid grey",
"height": "30px", "text-align": "center",
"background-color": "#9e9e9ea1", "width": "200px",
"text-align": "center" "height": "30px"
}); });
$(".md table th").css({
"border": "1px solid grey",
"width": "200px",
"height": "30px",
"background-color": "#9e9e9ea1",
"text-align": "center"
});
}
$(document).ready(function(){
HustOJVditor.renderMarkdownBlocks('.md', {
useTextContent: true
}).then(function () {
addMarkdownInputOutputLabels();
styleMarkdownTables();
}).catch(function (error) {
console.error('Failed to render discuss markdown.', error);
});
}); });
</script> </script>
<?php include("template/$OJ_TEMPLATE/footer.php");?> <?php include("template/$OJ_TEMPLATE/footer.php");?>

File diff suppressed because one or more lines are too long

View File

@@ -58,8 +58,7 @@ if ($pr_flag) {
} }
</style> </style>
<script src="<?php echo $OJ_CDN_URL . $path_fix . "template/$OJ_TEMPLATE/" ?>clipboard.min.js"></script> <script src="<?php echo $OJ_CDN_URL . $path_fix . "template/$OJ_TEMPLATE/" ?>clipboard.min.js"></script>
<script src="<?php echo $OJ_CDN_URL . $path_fix . "template/bs3/" ?>marked.min.js"></script> <script src="include/vditor-adapter.js"></script>
<script src="<?php echo $OJ_CDN_URL . $path_fix . "template/syzoj/js/" ?>markdown-it.min.js"></script>
<div class="padding "> <div class="padding ">
<div class="ui center aligned grid"> <div class="ui center aligned grid">
@@ -505,21 +504,34 @@ if ($pr_flag) {
} }
}); });
} }
function getFrameSourceValue(frameWindow) {
if (frameWindow.editor && typeof frameWindow.editor.getValue === 'function') {
return frameWindow.editor.getValue();
}
return frameWindow.$("#source").text();
}
function setFrameSourceValue(frameWindow, value) {
if (frameWindow.editor && typeof frameWindow.editor.setValue === 'function') {
frameWindow.editor.setValue(value);
return;
}
frameWindow.$("#source").text(value);
}
function selectOne(num, answer) { function selectOne(num, answer) {
let editor = $("iframe")[0].contentWindow.$("#source"); let frameWindow = $("iframe")[0].contentWindow;
let old = editor.text(); let old = getFrameSourceValue(frameWindow);
let key = num + ".*"; let key = num + ".*";
console.log(key); console.log(key);
let rep = old.replace(new RegExp(key), num + " " + answer); let rep = old.replace(new RegExp(key), num + " " + answer);
editor.text(rep); setFrameSourceValue(frameWindow, rep);
} }
function selectMulti(num, answer) { function selectMulti(num, answer) {
let editor = $("iframe")[0].contentWindow.$("#source"); let frameWindow = $("iframe")[0].contentWindow;
let old = editor.text(); let old = getFrameSourceValue(frameWindow);
let key = num + ".*"; let key = num + ".*";
console.log(key); console.log(key);
let rep = old.replace(new RegExp(key), num + " " + answer); let rep = old.replace(new RegExp(key), num + " " + answer);
editor.text(rep); setFrameSourceValue(frameWindow, rep);
} }
$(document).ready(function () { $(document).ready(function () {
@@ -574,47 +586,22 @@ if ($pr_flag) {
}); });
} }
<?php if (isset($OJ_MARKDOWN) && $OJ_MARKDOWN) { ?> function addMarkdownInputOutputLabels() {
marked.use({
// 开启异步渲染
async: true,
pedantic: false,
gfm: true,
mangle: false,
headerIds: false
});
// Helper function to decode HTML entities from Markdown source
function decodeHtmlEntities(text) {
var textArea = document.createElement('textarea');
textArea.innerHTML = text;
return textArea.value;
}
$(".md").each(function () {
let raw_markdown_source = $(this).html();
let decoded_markdown_source = decodeHtmlEntities(raw_markdown_source);
<?php if ( $OJ_MARKDOWN == "marked.js") { ?>
let markdown_content = marked.parse(decoded_markdown_source);
<?php } else if ($OJ_MARKDOWN == "markdown-it") { ?>
const md = window.markdownit();
md.set({
html: true,
linkify: true,
typographer: true,
});
let markdown_content = md.render(decoded_markdown_source);
<?php } ?>
$(this).html(markdown_content);
});
// adding note for ```input1 ```output1 in description
for (let i = 1; i < 10; i++) { for (let i = 1; i < 10; i++) {
$(".language-input" + i).parent().before("<div><?php echo $MSG_Input ?>" + i + ":</div>"); $(".language-input" + i).parent().each(function () {
$(".language-output" + i).parent().before("<div><?php echo $MSG_Output ?>" + i + ":</div>"); if ($(this).prev('.hustoj-md-io-label').length === 0) {
$(this).before("<div class='hustoj-md-io-label'><?php echo $MSG_Input ?>" + i + ":</div>");
}
});
$(".language-output" + i).parent().each(function () {
if ($(this).prev('.hustoj-md-io-label').length === 0) {
$(this).before("<div class='hustoj-md-io-label'><?php echo $MSG_Output ?>" + i + ":</div>");
}
});
} }
}
function styleMarkdownTables() {
$(".md table tr td").css({ $(".md table tr td").css({
"border": "1px solid grey", "border": "1px solid grey",
"text-align": "center", "text-align": "center",
@@ -629,98 +616,110 @@ if ($pr_flag) {
"background-color": "#9e9e9ea1", "background-color": "#9e9e9ea1",
"text-align": "center" "text-align": "center"
}); });
}
initMarkdownCodeCopy(); function renderProblemMarkdown() {
<?php if (isset($OJ_MARKDOWN) && $OJ_MARKDOWN) { ?>
return HustOJVditor.renderMarkdownBlocks('.md').then(function () {
addMarkdownInputOutputLabels();
styleMarkdownTables();
initMarkdownCodeCopy();
});
<?php } ?> <?php } ?>
//单纯文本1. A. B. C. D. 自动变控件 return Promise.resolve([]);
$('span[class=auto_select]').each(function () { }
let i = 1;
let start = 0; function initializeProblemChoices() {
let next = 0; $('span[class=auto_select]').each(function () {
let raw = $(this).html(); let i = 1;
let options = ['A', 'B', 'C', 'D']; let start = 0;
console.log("scanning..."); let next = 0;
while (start >= 0) { let raw = $(this).html();
start = raw.indexOf("\n" + i + ".", start); let options = ['A', 'B', 'C', 'D'];
if (start < 0) break; console.log("scanning...");
let end = start; while (start >= 0) {
let type = "radio" start = raw.indexOf("\n" + i + ".", start);
for (let j = 0; j < 4; j++) { if (start < 0) break;
let option = options[j]; let end = start;
end = raw.indexOf(option + ".", start); let type = "radio"
next = raw.indexOf("\n" + (i + 1) + ".", start); for (let j = 0; j < 4; j++) {
console.log("[" + raw.substring(start, end) + "]"); let option = options[j];
if (end < 0 || (end > next && next > 0)) { end = raw.indexOf(option + ".", start);
console.log("i:" + i + " j:" + option + " end:" + end + " next:" + next); next = raw.indexOf("\n" + (i + 1) + ".", start);
end = start; console.log("[" + raw.substring(start, end) + "]");
break; if (end < 0 || (end > next && next > 0)) {
console.log("i:" + i + " j:" + option + " end:" + end + " next:" + next);
end = start;
break;
}
if (j == 0 && raw.substring(start, end).indexOf("多选") > 0) type = "checkbox";
let disp = "<input type=\"" + type + "\" name=\"" + i + "\" value=\"" + option + "\" />" + option + ".";
raw = raw.substring(0, end - 1) + disp + raw.substring(end + 2);
start += disp.length;
} }
if (j == 0 && raw.substring(start, end).indexOf("多选") > 0) type = "checkbox"; start = end + 1;
let disp = "<input type=\"" + type + "\" name=\"" + i + "\" value=\"" + option + "\" />" + option + "."; i++;
//console.log(disp);
raw = raw.substring(0, end - 1) + disp + raw.substring(end + 2);
start += disp.length;
} }
start = end + 1; $(this).html(raw);
i++; });
}
//console.log(raw);
$(this).html(raw);
});
// subjective problems from hydroOJ markdown and embeded marks $('span[class="md auto_select"]').each(function () {
$('span[class="md auto_select"]').each(function () { let i = 1;
let i = 1; let options = ['A', 'B', 'C', 'D', 'E', 'F', 'G'];
let options = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; $(this).find("ul").each(function () {
$(this).find("ul").each(function () { let type = "radio";
let type = "radio"; let ol = $(this).prev("ol");
let ol = $(this).prev("ol"); if (ol != undefined && ol.attr("start") != undefined) i = ol.attr("start");
if (ol != undefined && ol.attr("start") != undefined) i = ol.attr("start"); console.log("id[" + i + "]");
console.log("id[" + i + "]"); if ($(this).html().indexOf("多选") > 0 || (ol != undefined && ol.html() != undefined && ol.html().indexOf("multiselect") > 0)) type = "checkbox";
if ($(this).html().indexOf("多选") > 0 || (ol != undefined && ol.html() != undefined && ol.html().indexOf("multiselect") > 0)) type = "checkbox"; let j = 0;
let j = 0; $(this).find("li").each(function () {
$(this).find("li").each(function () { let option = options[j];
let option = options[j]; let disp = "<input type=\"" + type + "\" name=\"" + i + "\" value=\"" + option + "\" />" + option + ".";
let disp = "<input type=\"" + type + "\" name=\"" + i + "\" value=\"" + option + "\" />" + option + "."; $(this).prepend(disp);
$(this).prepend(disp); j++;
//console.log(options[j]); });
j++; i++;
}); });
i++; let html = $(this).html();
for (; i > 0; i--) {
console.log("searching..." + i);
html = html.replace("{{ input(" + i + ") }}", "<input type='text' size=5 name='" + i + "' placeholder='第" + i + "题' ><br>");
}
html = html.replaceAll("", "&lt;");
html = html.replaceAll("", "&gt;");
$(this).html(html);
}); });
let html = $(this).html();
for (; i > 0; i--) {
console.log("searching..." + i);
html = html.replace("{{ input(" + i + ") }}", "<input type='text' size=5 name='" + i + "' placeholder='第" + i + "题' ><br>");
}
html = html.replaceAll("", "&lt;");
html = html.replaceAll("", "&gt;");
$(this).html(html);
});
$(".auto_select").find('input[type="text"]').change(function () {
$(".auto_select").find('input[type="text"]').change(function () {
selectOne($(this).attr("name"), $(this).val());
});
$('input[type="radio"]').click(function () {
if ($(this).is(':checked'))
selectOne($(this).attr("name"), $(this).val()); selectOne($(this).attr("name"), $(this).val());
}).css("width", "24px").css("height", "21px");
$('input[type="checkbox"]').click(function () {
let num = $(this).attr("name");
let answer = "";
$("input[type=checkbox][name=" + num + "]").each(function () {
if ($(this).is(':checked'))
answer += $(this).val();
}); });
selectMulti(num, answer);
}).css("width", "24px").css("height", "21px"); $('input[type="radio"]').click(function () {
if ($(this).is(':checked'))
selectOne($(this).attr("name"), $(this).val());
}).css("width", "24px").css("height", "21px");
$('input[type="checkbox"]').click(function () {
let num = $(this).attr("name");
let answer = "";
$("input[type=checkbox][name=" + num + "]").each(function () {
if ($(this).is(':checked'))
answer += $(this).val();
});
selectMulti(num, answer);
}).css("width", "24px").css("height", "21px");
<?php if ($row['spj'] > 1 || isset($_GET['sid']) || (isset($OJ_AUTO_SHOW_OFF) && $OJ_AUTO_SHOW_OFF)) { ?> <?php if ($row['spj'] > 1 || isset($_GET['sid']) || (isset($OJ_AUTO_SHOW_OFF) && $OJ_AUTO_SHOW_OFF)) { ?>
transform(); transform();
<?php } ?> <?php } ?>
}
window.renderProblemMarkdown = renderProblemMarkdown;
renderProblemMarkdown().catch(function (error) {
console.error('Failed to render problem markdown.', error);
}).then(function () {
initializeProblemChoices();
});
}); });
</script> </script>

View File

@@ -1,7 +1,7 @@
<?php $show_title=$id." - $MSG_ERROR_INFO - $OJ_NAME"; ?> <?php $show_title=$id." - $MSG_ERROR_INFO - $OJ_NAME"; ?>
<?php include("template/$OJ_TEMPLATE/header.php");?> <?php include("template/$OJ_TEMPLATE/header.php");?>
<script src="<?php echo "template/bs3/"?>marked.min.js"></script> <script src="include/vditor-adapter.js"></script>
<script src="template/<?php echo $OJ_TEMPLATE?>/js/textFit.min.js"></script> <script src="template/<?php echo $OJ_TEMPLATE?>/js/textFit.min.js"></script>
<style> <style>
.single-subtask { .single-subtask {
@@ -98,82 +98,78 @@
</script> </script>
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?> <?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/bs3/"?>marked.min.js"></script>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
marked.use({ HustOJVditor.renderMarkdownBlocks('#errtxt', {
// 开启异步渲染 getSource: function (element) {
async: true, var pre = element.querySelector ? element.querySelector('pre') : null;
pedantic: false, return pre ? pre.textContent : element.textContent || '';
gfm: true, }
mangle: false, }).then(function () {
headerIds: false for(let i=1;i<10;i++){
}); $(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$("#errtxt").each(function(){ $(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
// $(this).html(marked.parse($(this).html()));
});
// adding note for ```input1 ```output1 in description
for(let i=1;i<10;i++){
$(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
}
$("#errtxt table").addClass("ui mini-table cell striped");
$("#errtxt table tr:odd td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"background-color": "#8521d022",
"height": "30px"
});
$("#errtxt table tr:even td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"background-color": "#2185d022",
"height": "30px"
});
$("#errtxt table th").css({
"border": "1px solid grey",
"width": "200px",
"height": "30px",
"background-color": "#2185d088",
"text-align": "center"
});
<?php
if(isset($OJ_DOWNLOAD)&&$OJ_DOWNLOAD){
if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){
?>
let down=$($("#errtxt").find("h2")[0]);
let filename=down.text();
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
<?php
}else{
?>
$("#errtxt").find("h2").each(function(){
let down=$(this);
let filename=down.text();
console.log(filename);
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
});
<?php
} }
}
?>
$("th").each(function(){
let html=$(this).html();
html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>");
html=html.replace("Yours","<?php echo $MSG_YOURS ?>");
html=html.replace("filename","<?php echo $MSG_FILENAME ?>");
html=html.replace("size","<?php echo $MSG_SIZE ?>");
html=html.replace("result","<?php echo $MSG_RESULT ?>");
html=html.replace("memory","<?php echo $MSG_MEMORY?>");
html=html.replace("time","<?php echo $MSG_TIME ?>");
$(this).html(html);
});
$("#errtxt table").addClass("ui mini-table cell striped");
$("#errtxt table tr:odd td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"background-color": "#8521d022",
"height": "30px"
});
$("#errtxt table tr:even td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"background-color": "#2185d022",
"height": "30px"
});
$("#errtxt table th").css({
"border": "1px solid grey",
"width": "200px",
"height": "30px",
"background-color": "#2185d088",
"text-align": "center"
});
<?php
if(isset($OJ_DOWNLOAD)&&$OJ_DOWNLOAD){
if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){
?>
let down=$($("#errtxt").find("h2")[0]);
let filename=down.text();
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
<?php
}else{
?>
$("#errtxt").find("h2").each(function(){
let down=$(this);
let filename=down.text();
console.log(filename);
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
});
<?php
}
}
?>
$("th").each(function(){
let html=$(this).html();
html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>");
html=html.replace("Yours","<?php echo $MSG_YOURS ?>");
html=html.replace("filename","<?php echo $MSG_FILENAME ?>");
html=html.replace("size","<?php echo $MSG_SIZE ?>");
html=html.replace("result","<?php echo $MSG_RESULT ?>");
html=html.replace("memory","<?php echo $MSG_MEMORY?>");
html=html.replace("time","<?php echo $MSG_TIME ?>");
$(this).html(html);
});
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
});
}); });

View File

@@ -423,19 +423,19 @@ function loadFromBlockly(){
} }
?> ?>
<?php if($OJ_ACE_EDITOR){ ?> <?php if($OJ_ACE_EDITOR){ ?>
<script src="<?php echo $OJ_CDN_URL?>ace/ace.js"></script> <script src="include/vditor-adapter.js"></script>
<script src="<?php echo $OJ_CDN_URL?>ace/ext-language_tools.js"></script>
<script> <script>
ace.require("ace/ext/language_tools"); var editor = HustOJVditor.createDeferredCodeEditor({
var editor = ace.edit("source"); container: "source",
editor.setTheme("ace/theme/xcode"); hiddenField: "hide_source",
theme: "ace/theme/xcode",
fontSize: 18
});
switchLang(<?php echo $lastlang ?>); switchLang(<?php echo $lastlang ?>);
editor.setOptions({ editor.setOptions({
enableBasicAutocompletion: true, enableBasicAutocompletion: true,
enableSnippets: true, enableSnippets: true,
enableLiveAutocompletion: true, //改为true,打开自动补齐功能改为false关闭 enableLiveAutocompletion: true,
// fontFamily: "Consolas", // MacOS missing align
// theme: "ace/theme/ambiance", // Black theme
fontSize: "18px" fontSize: "18px"
}); });
reloadtemplate($("#language").val()); reloadtemplate($("#language").val());