md编辑器增加br

video_log
harry 5 years ago
parent 10834cab32
commit 275948048e

@ -1,34 +1,16 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import {Input, Select, Radio, Checkbox, Popconfirm, message, Modal} from 'antd'; import { getUploadActionUrl, getUrl } from 'educoder';
import {BrowserRouter as Router, Route, Link, Switch} from "react-router-dom";
// import "antd/dist/antd.css";
import { getImageUrl, getUploadActionUrl, getUrl } from 'educoder';
import '../../courses/css/Courses.css' import '../../courses/css/Courses.css'
import axios from 'axios';
import './css/TPMchallengesnew.css'; import './css/TPMchallengesnew.css';
require('codemirror/lib/codemirror.css'); require('codemirror/lib/codemirror.css');
let origin = getUrl();
let path = '/editormd/lib/' let path = '/editormd/lib/'
path = getUrl("/editormd/lib/") path = getUrl("/editormd/lib/")
const $ = window.$; const $ = window.$;
let timeout;
let currentValue;
const Option = Select.Option;
const RadioGroup = Radio.Group;
// 保存数据 // 保存数据
function md_add_data(k, mdu, d) { function md_add_data(k, mdu, d) {
@ -107,7 +89,7 @@ function create_editorMD(id, width, high, placeholder, imageUrl, callback, initV
var editorName = window.editormd(id, { var editorName = window.editormd(id, {
width: width, width: width,
height: high === undefined ? 400 : high, height: high === undefined ? 400 : high,
path: path, // "/editormd/lib/" path: getUrl("/editormd/lib/"), // "/editormd/lib/"
markdown: initValue, markdown: initValue,
dialogLockScreen: false, dialogLockScreen: false,
@ -123,21 +105,35 @@ function create_editorMD(id, width, high, placeholder, imageUrl, callback, initV
sequenceDiagram: true, sequenceDiagram: true,
autoFocus: false, autoFocus: false,
// mine
toolbarIcons: function (mdEditor) { toolbarIcons: function (mdEditor) {
let react_id = `react_${mdEditor.id}`; let react_id = `react_${mdEditor.id}`;
const __that = window[react_id] const __that = window[react_id]
// Or return editormd.toolbarModes[name]; // full, simple, mini
// Using "||" set icons align right. // Using "||" set icons align right.
const icons = ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "link", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear"]; const icons = ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "link", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "line-break", "watch", "clear"];
// 试卷处用到的填空题新增按钮 // 试卷处用到的填空题新增按钮
if (__that.props.showNullButton) { if (__that.props.showNullButton) {
icons.push('nullBtton') icons.push('nullBtton')
} }
return icons return icons
}, },
toolbarIconsClass: {
"line-break": "fa-minus"
},
toolbarHandlers: {
/**
* @param {Object} cm CodeMirror对象
* @param {Object} icon 图标按钮jQuery元素对象
* @param {Object} cursor CodeMirror的光标对象可获取光标所在行和位置
* @param {String} selection 编辑器选中的文本
*/
"line-break": function (cm, icon, cursor, selection) {
// 如果当前没有选中的文本,将光标移到要输入的位置
if (selection === "") {
cm.setCursor(cursor.line, cursor.ch + 1)
}
cm.replaceSelection("<br/>");
}
},
toolbarCustomIcons: { toolbarCustomIcons: {
testIcon: "<a type=\"inline\" class=\"latex\" ><div class='zbg'></div></a>", testIcon: "<a type=\"inline\" class=\"latex\" ><div class='zbg'></div></a>",
testIcon1: "<a type=\"latex\" class=\"latex\" ><div class='zbg_latex'></div></a>", testIcon1: "<a type=\"latex\" class=\"latex\" ><div class='zbg_latex'></div></a>",
@ -157,9 +153,6 @@ function create_editorMD(id, width, high, placeholder, imageUrl, callback, initV
let _editorName = this; let _editorName = this;
let react_id = `react_${_editorName.id}`; let react_id = `react_${_editorName.id}`;
const __that = window[react_id] const __that = window[react_id]
// this.previewing();
// let _id = id;
$("#" + _id + " [type=\"latex\"]").bind("click", function () { $("#" + _id + " [type=\"latex\"]").bind("click", function () {
_editorName.cm.replaceSelection("```latex"); _editorName.cm.replaceSelection("```latex");
_editorName.cm.replaceSelection("\n"); _editorName.cm.replaceSelection("\n");
@ -180,19 +173,12 @@ function create_editorMD(id, width, high, placeholder, imageUrl, callback, initV
if (__that.props.showNullButton) { if (__that.props.showNullButton) {
const NULL_CH = '▁' const NULL_CH = '▁'
// const NULL_CH = ''
// const NULL_CH = '🈳'
$("#" + _id + " [type=\"nullBtton\"]").bind("click", function () { $("#" + _id + " [type=\"nullBtton\"]").bind("click", function () {
_editorName.cm.replaceSelection(NULL_CH); _editorName.cm.replaceSelection(NULL_CH);
// var __Cursor = _editorName.cm.getDoc().getCursor();
// _editorName.cm.setCursor(__Cursor.line - 1, 0);
}); });
} }
if (noStorage == true) { if (!noStorage == true) {
} else {
md_elocalStorage(_editorName, `MDEditor__${_id}`, _id); md_elocalStorage(_editorName, `MDEditor__${_id}`, _id);
} }

Loading…
Cancel
Save