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

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -85,7 +85,7 @@ static $OJ_RANK_HIDDEN="'admin','super','szx','sen'"; // 管理员不显示在
static $OJ_FRIENDLY_LEVEL=0; //系统友好级别暂定0-9级级别越高越傻瓜系统易用度高的同时将降低安全性仅供非专业用途造成泄题、抄袭概不负责。
static $OJ_FREE_PRACTICE=true; //自由练习,不受比赛作业用题限制
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_DIV_FILTER=true; // 过滤题面中的div修复显示异常特别是来自其他OJ系统的题面。
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" />
<link rel="stylesheet" href="../kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="../kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="../kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="../kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="../kindeditor/plugins/code/prettify.js"></script>
<script src="../include/vditor-adapter.js"></script>
<script>
KindEditor.ready(function(K) {
var editor1 = K.create('textarea[class="kindeditor"]', {
width : '100%',
cssPath : '../kindeditor/plugins/code/prettify.css',
uploadJson : '../kindeditor/php/upload_json.php',
fileManagerJson : '../kindeditor/php/file_manager_json.php',
allowFileManager : false,
afterCreate : function() {
var self = this;
K.ctrl(document, 13, function() {
self.sync();
K('form[name=example]')[0].submit();
});
K.ctrl(self.edit.doc, 13, function() {
self.sync();
K('form[name=example]')[0].submit();
});
$(document).ready(function () {
HustOJVditor.initTextareaVditors({
selector: 'textarea.kindeditor',
uploadUrl: '../kindeditor/php/upload_json.php',
accept: '*/*',
mode: 'sv',
ctrlEnterFormName: 'example',
preview: {
mode: 'both',
delay: 0,
actions: [],
markdown: {
sanitize: false,
autoSpace: false,
fixTermTypo: false
}
}
}).catch(function (error) {
console.error('Failed to initialize Vditor.', error);
});
// prettyPrint();
});
</script>

View File

@@ -2,7 +2,7 @@
<script src="<?php echo $OJ_CDN_URL.$path_fix."include/"?>jquery-latest.js"></script>
<?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 } ?>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->

File diff suppressed because one or more lines are too long

View File

@@ -246,30 +246,42 @@
}
} );
}
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){
let editor = $("iframe")[0].contentWindow.$("#source");
let old=editor.text();
let frameWindow = $("iframe")[0].contentWindow;
let old=getFrameSourceValue(frameWindow);
let key= num+".*";
console.log(key);
let rep=old.replace(new RegExp(key),num+" "+answer);
editor.text(rep);
setFrameSourceValue(frameWindow, rep);
}
function selectMulti( num, answer){
let editor = $("iframe")[0].contentWindow.$("#source");
let old=editor.text();
let frameWindow = $("iframe")[0].contentWindow;
let old=getFrameSourceValue(frameWindow);
let key= num+".*";
console.log(key);
let rep=old.replace(new RegExp(key),num+" "+answer);
editor.text(rep);
setFrameSourceValue(frameWindow, rep);
}
$( document ).ready( function () {
$( "#creator" ).load( "problem-ajax.php?pid=<?php echo $id?>" );
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
$(".md").each(function(){
$(this).html(marked.parse($(this).html()));
});
<?php } ?>
//单纯文本1. A. B. C. D. 自动变控件
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;
@@ -286,14 +298,12 @@
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(){
@@ -311,9 +321,18 @@
});
selectMulti(num,answer);
});
<?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();
<?php }?>
<?php }?>
}
window.renderProblemMarkdown = renderProblemMarkdown;
$( document ).ready( function () {
$( "#creator" ).load( "problem-ajax.php?pid=<?php echo $id?>" );
renderProblemMarkdown().catch(function (error) {
console.error('Failed to render problem markdown.', error);
}).then(function () {
initializeProblemChoices();
});
} );

View File

@@ -39,21 +39,14 @@
<?php include("template/$OJ_TEMPLATE/js.php");?>
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/bs3/"?>marked.min.js"></script>
<script>
$(document).ready(function(){
marked.use({
// 开启异步渲染
async: true,
pedantic: false,
gfm: true,
mangle: false,
headerIds: false
});
$("#errtxt").each(function(){
$(this).html(marked.parse($(this).html()));
});
// adding note for ```input1 ```output1 in description
HustOJVditor.renderMarkdownBlocks('#errtxt', {
getSource: function (element) {
var pre = element.querySelector ? element.querySelector('pre') : null;
return pre ? pre.textContent : element.textContent || '';
}
}).then(function () {
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>");
@@ -115,7 +108,9 @@
$(this).html(html);
});
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
});
});
</script>

View File

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

View File

@@ -7,11 +7,8 @@
$("#csrf").load("<?php echo $path_fix ?>csrf.php");
</script>
<!-- WangEditor编辑器文件-->
<script src="./template/bshark/wangEditor/wangEditor.min.js"></script>
<?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 } ?>
<!-- 主题核心js -->

View File

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

View File

@@ -59,21 +59,15 @@
explain();
</script>
<?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>
$(document).ready(function(){
marked.use({
// 开启异步渲染
async: true,
pedantic: false,
gfm: true,
mangle: false,
headerIds: false
});
$("#errtxt").each(function(){
$(this).html(marked.parse($(this).html()));
});
// adding note for ```input1 ```output1 in description
HustOJVditor.renderMarkdownBlocks('#errtxt', {
getSource: function (element) {
var pre = element.querySelector ? element.querySelector('pre') : null;
return pre ? pre.textContent : element.textContent || '';
}
}).then(function () {
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>");
@@ -135,7 +129,9 @@
$(this).html(html);
});
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
});
});
</script>

View File

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

View File

@@ -58,21 +58,15 @@
explain();
</script>
<?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>
$(document).ready(function(){
marked.use({
// 开启异步渲染
async: true,
pedantic: false,
gfm: true,
mangle: false,
headerIds: false
});
$("#errtxt").each(function(){
$(this).html(marked.parse($(this).html()));
});
// adding note for ```input1 ```output1 in description
HustOJVditor.renderMarkdownBlocks('#errtxt', {
getSource: function (element) {
var pre = element.querySelector ? element.querySelector('pre') : null;
return pre ? pre.textContent : element.textContent || '';
}
}).then(function () {
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>");
@@ -134,7 +128,9 @@
$(this).html(html);
});
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
});
});
</script>

View File

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

View File

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

View File

@@ -7,7 +7,7 @@
?>
<?php include("template/$OJ_TEMPLATE/header.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">
<h1><?php echo $news_title ?></h1>
<div class="ui existing segment">
@@ -15,23 +15,22 @@
</div>
</div>
<script>
$(document).ready(function(){
marked.use({
// 开启异步渲染
async: true,
pedantic: false,
gfm: true,
mangle: false,
headerIds: false
});
$(".md").each(function(){
$(this).html(marked.parse($(this).text()));
});
// adding note for ```input1 ```output1 in description
function addMarkdownInputOutputLabels() {
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>");
$(".language-input"+i).parent().each(function(){
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({
"border": "1px solid grey",
"text-align": "center",
@@ -46,6 +45,17 @@
"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>
<?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>
<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="<?php echo $OJ_CDN_URL.$path_fix."template/syzoj/js/"?>markdown-it.min.js"></script>
<script src="include/vditor-adapter.js"></script>
<div class="padding ">
<div class="ui center aligned grid">
@@ -399,50 +398,55 @@ 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){
let editor = $("iframe")[0].contentWindow.$("#source");
let old=editor.text();
let frameWindow = $("iframe")[0].contentWindow;
let old=getFrameSourceValue(frameWindow);
let key= num+".*";
console.log(key);
let rep=old.replace(new RegExp(key),num+" "+answer);
editor.text(rep);
setFrameSourceValue(frameWindow, rep);
}
function selectMulti( num, answer){
let editor = $("iframe")[0].contentWindow.$("#source");
let old=editor.text();
let frameWindow = $("iframe")[0].contentWindow;
let old=getFrameSourceValue(frameWindow);
let key= num+".*";
console.log(key);
let rep=old.replace(new RegExp(key),num+" "+answer);
editor.text(rep);
setFrameSourceValue(frameWindow, rep);
}
$(document).ready(function(){
$("#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(){
<?php if ($OJ_MARKDOWN && $OJ_MARKDOWN=="marked.js") {?>
$(this).html(marked.parse($(this).html()));
<?php }else if ($OJ_MARKDOWN && $OJ_MARKDOWN=="markdown-it") {?>
const md = window.markdownit();
$(this).html(md.render($(this).text()));
<?php } ?>
function addMarkdownInputOutputLabels() {
for (let i = 1; i < 10; i++) {
$(".language-input" + i).parent().each(function(){
if ($(this).prev('.hustoj-md-io-label').length === 0) {
$(this).before("<div class='hustoj-md-io-label'><?php echo $MSG_Input?>" + i + ":</div>");
}
});
// 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>");
$(".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({
"border": "1px solid grey",
"text-align": "center",
@@ -457,9 +461,19 @@ function selectMulti( num, answer){
"background-color": "#9e9e9ea1",
"text-align": "center"
});
}
function renderProblemMarkdown() {
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
return HustOJVditor.renderMarkdownBlocks('.md').then(function () {
addMarkdownInputOutputLabels();
styleMarkdownTables();
});
<?php } ?>
//单纯文本1. A. B. C. D. 自动变控件
return Promise.resolve([]);
}
function initializeProblemChoices() {
$('span[class=auto_select]').each(function(){
let i=1;
let start=0;
@@ -484,18 +498,15 @@ function selectMulti( num, answer){
}
if(j==0&&raw.substring(start,end).indexOf("多选")>0) type="checkbox";
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);
});
// subjective problems from hydroOJ markdown and embeded marks
$('span[class="md auto_select"]').each(function(){
let i=1;
let options=['A','B','C','D','E','F','G'];
@@ -510,7 +521,6 @@ function selectMulti( num, answer){
let option=options[j];
let disp="<input type=\""+type+"\" name=\""+i+"\" value=\""+option+"\" />"+option+".";
$(this).prepend(disp);
//console.log(options[j]);
j++;
});
i++;
@@ -525,12 +535,10 @@ function selectMulti( num, answer){
$(this).html(html);
});
$(".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());
@@ -547,6 +555,15 @@ function 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;
renderProblemMarkdown().catch(function (error) {
console.error('Failed to render problem markdown.', error);
}).then(function () {
initializeProblemChoices();
});
});
</script>

View File

@@ -1,7 +1,7 @@
<?php $show_title=$id." - $MSG_ERROR_INFO - $OJ_NAME"; ?>
<?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>
<style>
.single-subtask {
@@ -92,21 +92,14 @@
</script>
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/bs3/"?>marked.min.js"></script>
<script>
$(document).ready(function(){
marked.use({
// 开启异步渲染
async: true,
pedantic: false,
gfm: true,
mangle: false,
headerIds: false
});
$("#errtxt").each(function(){
$(this).html(marked.parse($(this).html()));
});
// adding note for ```input1 ```output1 in description
HustOJVditor.renderMarkdownBlocks('#errtxt', {
getSource: function (element) {
var pre = element.querySelector ? element.querySelector('pre') : null;
return pre ? pre.textContent : element.textContent || '';
}
}).then(function () {
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>");
@@ -168,7 +161,9 @@
$(this).html(html);
});
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
});
});
</script>

View File

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

View File

@@ -77,21 +77,15 @@
</script>
<?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>
$(document).ready(function(){
marked.use({
// 开启异步渲染
async: true,
pedantic: false,
gfm: true,
mangle: false,
headerIds: false
});
$("#errtxt").each(function(){
$(this).html(marked.parse($(this).html()));
});
// adding note for ```input1 ```output1 in description
HustOJVditor.renderMarkdownBlocks('#errtxt', {
getSource: function (element) {
var pre = element.querySelector ? element.querySelector('pre') : null;
return pre ? pre.textContent : element.textContent || '';
}
}).then(function () {
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>");
@@ -153,7 +147,9 @@
$(this).html(html);
});
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
});
});
</script>

View File

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

View File

@@ -7,7 +7,7 @@
?>
<?php include("template/$OJ_TEMPLATE/header.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">
<h1><?php echo $news_title ?></h1>
<div class="ui existing segment">
@@ -15,23 +15,22 @@
</div>
</div>
<script>
$(document).ready(function(){
marked.use({
// 开启异步渲染
async: true,
pedantic: false,
gfm: true,
mangle: false,
headerIds: false
});
$(".md").each(function(){
$(this).html(marked.parse($(this).text()));
});
// adding note for ```input1 ```output1 in description
function addMarkdownInputOutputLabels() {
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>");
$(".language-input"+i).parent().each(function(){
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({
"border": "1px solid grey",
"text-align": "center",
@@ -46,6 +45,17 @@
"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>
<?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>
<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="<?php echo $OJ_CDN_URL . $path_fix . "template/syzoj/js/" ?>markdown-it.min.js"></script>
<script src="include/vditor-adapter.js"></script>
<div class="padding ">
<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) {
let editor = $("iframe")[0].contentWindow.$("#source");
let old = editor.text();
let frameWindow = $("iframe")[0].contentWindow;
let old = getFrameSourceValue(frameWindow);
let key = num + ".*";
console.log(key);
let rep = old.replace(new RegExp(key), num + " " + answer);
editor.text(rep);
setFrameSourceValue(frameWindow, rep);
}
function selectMulti(num, answer) {
let editor = $("iframe")[0].contentWindow.$("#source");
let old = editor.text();
let frameWindow = $("iframe")[0].contentWindow;
let old = getFrameSourceValue(frameWindow);
let key = num + ".*";
console.log(key);
let rep = old.replace(new RegExp(key), num + " " + answer);
editor.text(rep);
setFrameSourceValue(frameWindow, rep);
}
$(document).ready(function () {
@@ -574,47 +586,22 @@ if ($pr_flag) {
});
}
<?php if (isset($OJ_MARKDOWN) && $OJ_MARKDOWN) { ?>
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
function addMarkdownInputOutputLabels() {
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>");
$(".language-input" + i).parent().each(function () {
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({
"border": "1px solid grey",
"text-align": "center",
@@ -629,11 +616,20 @@ if ($pr_flag) {
"background-color": "#9e9e9ea1",
"text-align": "center"
});
}
function renderProblemMarkdown() {
<?php if (isset($OJ_MARKDOWN) && $OJ_MARKDOWN) { ?>
return HustOJVditor.renderMarkdownBlocks('.md').then(function () {
addMarkdownInputOutputLabels();
styleMarkdownTables();
initMarkdownCodeCopy();
});
<?php } ?>
//单纯文本1. A. B. C. D. 自动变控件
return Promise.resolve([]);
}
function initializeProblemChoices() {
$('span[class=auto_select]').each(function () {
let i = 1;
let start = 0;
@@ -658,18 +654,15 @@ if ($pr_flag) {
}
if (j == 0 && raw.substring(start, end).indexOf("多选") > 0) type = "checkbox";
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);
});
// subjective problems from hydroOJ markdown and embeded marks
$('span[class="md auto_select"]').each(function () {
let i = 1;
let options = ['A', 'B', 'C', 'D', 'E', 'F', 'G'];
@@ -684,7 +677,6 @@ if ($pr_flag) {
let option = options[j];
let disp = "<input type=\"" + type + "\" name=\"" + i + "\" value=\"" + option + "\" />" + option + ".";
$(this).prepend(disp);
//console.log(options[j]);
j++;
});
i++;
@@ -699,12 +691,10 @@ if ($pr_flag) {
$(this).html(html);
});
$(".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());
@@ -721,6 +711,15 @@ if ($pr_flag) {
<?php if ($row['spj'] > 1 || isset($_GET['sid']) || (isset($OJ_AUTO_SHOW_OFF) && $OJ_AUTO_SHOW_OFF)) { ?>
transform();
<?php } ?>
}
window.renderProblemMarkdown = renderProblemMarkdown;
renderProblemMarkdown().catch(function (error) {
console.error('Failed to render problem markdown.', error);
}).then(function () {
initializeProblemChoices();
});
});
</script>

View File

@@ -1,7 +1,7 @@
<?php $show_title=$id." - $MSG_ERROR_INFO - $OJ_NAME"; ?>
<?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>
<style>
.single-subtask {
@@ -98,21 +98,14 @@
</script>
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
<script src="<?php echo $OJ_CDN_URL.$path_fix."template/bs3/"?>marked.min.js"></script>
<script>
$(document).ready(function(){
marked.use({
// 开启异步渲染
async: true,
pedantic: false,
gfm: true,
mangle: false,
headerIds: false
});
$("#errtxt").each(function(){
// $(this).html(marked.parse($(this).html()));
});
// adding note for ```input1 ```output1 in description
HustOJVditor.renderMarkdownBlocks('#errtxt', {
getSource: function (element) {
var pre = element.querySelector ? element.querySelector('pre') : null;
return pre ? pre.textContent : element.textContent || '';
}
}).then(function () {
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>");
@@ -174,6 +167,9 @@
$(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){ ?>
<script src="<?php echo $OJ_CDN_URL?>ace/ace.js"></script>
<script src="<?php echo $OJ_CDN_URL?>ace/ext-language_tools.js"></script>
<script src="include/vditor-adapter.js"></script>
<script>
ace.require("ace/ext/language_tools");
var editor = ace.edit("source");
editor.setTheme("ace/theme/xcode");
var editor = HustOJVditor.createDeferredCodeEditor({
container: "source",
hiddenField: "hide_source",
theme: "ace/theme/xcode",
fontSize: 18
});
switchLang(<?php echo $lastlang ?>);
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true, //改为true,打开自动补齐功能改为false关闭
// fontFamily: "Consolas", // MacOS missing align
// theme: "ace/theme/ambiance", // Black theme
enableLiveAutocompletion: true,
fontSize: "18px"
});
reloadtemplate($("#language").val());