markdown.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. $(function () {
  2. window.isLoad = true;
  3. editormd.katexURL = {
  4. js : window.baseUrl + "/static/katex/katex",
  5. css : window.baseUrl + "/static/katex/katex"
  6. };
  7. window.addDocumentModalFormHtml = $(this).find("form").html();
  8. window.editor = editormd("docEditor", {
  9. width: "100%",
  10. height: "100%",
  11. path: window.baseUrl + "/static/editor.md/lib/",
  12. toolbar: true,
  13. placeholder: "本编辑器支持 Markdown 编辑,左边编写,右边预览。",
  14. imageUpload: true,
  15. imageFormats: ["jpg", "jpeg", "gif", "png", "JPG", "JPEG", "GIF", "PNG"],
  16. imageUploadURL: window.imageUploadURL,
  17. toolbarModes: "full",
  18. fileUpload: true,
  19. fileUploadURL: window.fileUploadURL,
  20. taskList: true,
  21. flowChart: true,
  22. htmlDecode: "style,script,iframe,title,onmouseover,onmouseout,style",
  23. lineNumbers: false,
  24. sequenceDiagram: true,
  25. tocStartLevel: 1,
  26. tocm: true,
  27. tex:true,
  28. saveHTMLToTextarea: true,
  29. onload: function() {
  30. this.hideToolbar();
  31. var keyMap = {
  32. "Ctrl-S": function(cm) {
  33. saveDocument(false);
  34. },
  35. "Cmd-S": function(cm){
  36. saveDocument(false);
  37. },
  38. "Ctrl-A": function(cm) {
  39. cm.execCommand("selectAll");
  40. }
  41. };
  42. this.addKeyMap(keyMap);
  43. var $select_node_id = window.treeCatalog.get_selected();
  44. if ($select_node_id) {
  45. var $select_node = window.treeCatalog.get_node($select_node_id[0])
  46. if ($select_node) {
  47. $select_node.node = {
  48. id: $select_node.id
  49. };
  50. loadDocument($select_node);
  51. }
  52. }
  53. uploadImage("docEditor", function ($state, $res) {
  54. if ($state === "before") {
  55. return layer.load(1, {
  56. shade: [0.1, '#fff'] // 0.1 透明度的白色背景
  57. });
  58. } else if ($state === "success") {
  59. if ($res.errcode === 0) {
  60. var value = '![](' + $res.url + ')';
  61. window.editor.insertValue(value);
  62. }
  63. }
  64. });
  65. },
  66. onchange: function () {
  67. resetEditorChanged(true);
  68. }
  69. });
  70. /**
  71. * 实现标题栏操作
  72. */
  73. $("#editormd-tools").on("click", "a[class!='disabled']", function () {
  74. if($(this).hasClass('disabled')){
  75. return false;
  76. }
  77. var name = $(this).find("i").attr("name");
  78. if (name === "attachment") {
  79. $("#uploadAttachModal").modal("show");
  80. } else if (name === "history") {
  81. window.documentHistory();
  82. } else if (name === "save") {
  83. saveDocument(false);
  84. } else if (name === "template") {
  85. $("#documentTemplateModal").modal("show");
  86. } else if (name=="word2md"){
  87. $("#word2mdform")[0].reset();
  88. $("#output").html("");
  89. $("#messages").html("");
  90. $("#word2md").modal("show");
  91. }else if (name=="Pasteoffice"){
  92. $("#Pasteofficeform")[0].reset();
  93. $("#Pastearea").innerText="";
  94. $("#officeoutmd").val("");
  95. $("#Pasteoffice").modal("show");
  96. }else if (name === "sidebar") {
  97. $("#manualCategory").toggle(0, "swing", function () {
  98. var $then = $("#manualEditorContainer");
  99. var left = parseInt($then.css("left"));
  100. if (left > 0) {
  101. window.editorContainerLeft = left;
  102. $then.css("left", "0");
  103. } else {
  104. $then.css("left", window.editorContainerLeft + "px");
  105. }
  106. window.editor.resize();
  107. });
  108. } else if (name === "release") {
  109. if (Object.prototype.toString.call(window.documentCategory) === '[object Array]' && window.documentCategory.length > 0) {
  110. if ($("#markdown-save").hasClass('change')) {
  111. var comfirm_result = confirm("编辑内容未保存,需要保存吗?")
  112. if (comfirm_result) {
  113. saveDocument(false, releaseBook);
  114. return;
  115. }
  116. }
  117. releaseBook();
  118. } else {
  119. layer.msg("没有需要发布的文档")
  120. }
  121. } else if (name === "tasks") {
  122. // 插入 GFM 任务列表
  123. var cm = window.editor.cm;
  124. var selection = cm.getSelection();
  125. if (selection === "") {
  126. cm.replaceSelection("- [x] " + selection);
  127. } else {
  128. var selectionText = selection.split("\n");
  129. for (var i = 0, len = selectionText.length; i < len; i++) {
  130. selectionText[i] = (selectionText[i] === "") ? "" : "- [x] " + selectionText[i];
  131. }
  132. cm.replaceSelection(selectionText.join("\n"));
  133. }
  134. } else {
  135. var action = window.editor.toolbarHandlers[name];
  136. if (action !== "undefined") {
  137. $.proxy(action, window.editor)();
  138. window.editor.focus();
  139. }
  140. }
  141. }) ;
  142. /***
  143. * 加载指定的文档到编辑器中
  144. * @param $node
  145. */
  146. window.loadDocument = function($node) {
  147. var index = layer.load(1, {
  148. shade: [0.1, '#fff'] // 0.1 透明度的白色背景
  149. });
  150. $.get(window.editURL + $node.node.id ).done(function (res) {
  151. layer.close(index);
  152. if (res.errcode === 0) {
  153. var node = { "id": res.data.doc_id, 'parent': res.data.parent_id === 0 ? '#' : res.data.parent_id, "text": res.data.doc_name, "identify": res.data.identify, "version": res.data.version };
  154. if(res.data.is_lock){
  155. node.type = "lock";
  156. node.text = node.text + "<span class='lock-text'> [锁定]</span>";
  157. window.editor.config('readOnly',true);
  158. }else{
  159. node.type = "unlock";
  160. window.editor.config('readOnly',false);
  161. }
  162. window.isLoad = true;
  163. try {
  164. window.editor.clear();
  165. if(res.data.markdown !== ""){
  166. window.editor.insertValue(res.data.markdown);
  167. }else{
  168. window.isLoad = true;
  169. }
  170. window.editor.setCursor({line: 0, ch: 0});
  171. }catch(e){
  172. console.log(e);
  173. }
  174. pushDocumentCategory(node);
  175. window.selectNode = node;
  176. pushVueLists(res.data.attach);
  177. } else {
  178. layer.msg("文档加载失败");
  179. }
  180. }).fail(function () {
  181. layer.close(index);
  182. layer.msg("文档加载失败");
  183. });
  184. };
  185. /**
  186. * 保存文档到服务器
  187. * @param $is_cover 是否强制覆盖
  188. */
  189. function saveDocument($is_cover, callback) {
  190. var index = null;
  191. var node = window.selectNode;
  192. var content = window.editor.getMarkdown();
  193. var html = window.editor.getPreviewedHTML();
  194. var version = "";
  195. if (!node) {
  196. layer.msg("获取当前文档信息失败");
  197. return;
  198. }
  199. var doc_id = parseInt(node.id);
  200. for (var i in window.documentCategory) {
  201. var item = window.documentCategory[i];
  202. if (item.id === doc_id) {
  203. version = item.version;
  204. break;
  205. }
  206. }
  207. $.ajax({
  208. beforeSend: function () {
  209. index = layer.load(1, { shade: [0.1, '#fff'] });
  210. },
  211. url: window.editURL,
  212. data: { "identify": window.book.identify, "doc_id": doc_id, "markdown": content, "html": html, "cover": $is_cover ? "yes" : "no", "version": version },
  213. type: "post",
  214. timeout : 30000,
  215. dataType: "json",
  216. success: function (res) {
  217. layer.close(index);
  218. if (res.errcode === 0) {
  219. resetEditorChanged(false);
  220. for (var i in window.documentCategory) {
  221. var item = window.documentCategory[i];
  222. if (item.id === doc_id) {
  223. window.documentCategory[i].version = res.data.version;
  224. break;
  225. }
  226. }
  227. if (typeof callback === "function") {
  228. callback();
  229. }
  230. } else if(res.errcode === 6005) {
  231. var confirmIndex = layer.confirm('文档已被其他人修改确定覆盖已存在的文档吗?', {
  232. btn: ['确定', '取消'] // 按钮
  233. }, function() {
  234. layer.close(confirmIndex);
  235. saveDocument(true, callback);
  236. });
  237. } else {
  238. layer.msg(res.message);
  239. }
  240. },
  241. error : function (XMLHttpRequest, textStatus, errorThrown) {
  242. layer.close(index);
  243. layer.msg("服务器错误:" + errorThrown);
  244. }
  245. });
  246. }
  247. /**
  248. * 设置编辑器变更状态
  249. * @param $is_change
  250. */
  251. function resetEditorChanged($is_change) {
  252. // console.log($is_change);
  253. // console.log(window.isLoad);
  254. if ($is_change && !window.isLoad) {
  255. var type = window.treeCatalog.get_type(window.selectNode);
  256. if(type === "lock"){
  257. return;
  258. }
  259. $("#markdown-save").removeClass('disabled').addClass('change');
  260. } else {
  261. $("#markdown-save").removeClass('change').addClass('disabled');
  262. }
  263. window.isLoad = false;
  264. }
  265. /**
  266. * 添加顶级文档
  267. */
  268. $("#addDocumentForm").ajaxForm({
  269. beforeSubmit: function () {
  270. var doc_name = $.trim($("#documentName").val());
  271. if (doc_name === "") {
  272. return showError("目录名称不能为空", "#add-error-message")
  273. }
  274. $("#btnSaveDocument").button("loading");
  275. return true;
  276. },
  277. success: function (res) {
  278. if (res.errcode === 0) {
  279. var data = { "id": res.data.doc_id, 'parent': res.data.parent_id === 0 ? '#' : res.data.parent_id , "text": res.data.doc_name, "identify": res.data.identify, "version": res.data.version ,"type": res.data.is_lock ? "lock" : "unlock"};
  280. if(res.data.is_lock){
  281. data.text = data.text + "<span class='lock-text'> [锁定]</span>";
  282. }
  283. var node = window.treeCatalog.get_node(data.id);
  284. if (node) {
  285. window.treeCatalog.rename_node({ "id": data.id }, data.text);
  286. } else {
  287. window.treeCatalog.create_node(data.parent, data);
  288. window.treeCatalog.deselect_all();
  289. window.treeCatalog.select_node(data);
  290. }
  291. pushDocumentCategory(data);
  292. $("#markdown-save").removeClass('change').addClass('disabled');
  293. $("#addDocumentModal").modal('hide');
  294. } else {
  295. showError(res.message, "#add-error-message");
  296. }
  297. $("#btnSaveDocument").button("reset");
  298. }
  299. });
  300. /**
  301. * 文档目录树
  302. */
  303. $("#sidebar").jstree({
  304. 'plugins': ["wholerow", "types", 'dnd', 'contextmenu'],
  305. "types": {
  306. "default": {
  307. "icon": false // 删除默认图标
  308. },
  309. "lock" : {
  310. "icon" : false
  311. },
  312. "unlock" : {
  313. "icon" : false
  314. }
  315. },
  316. 'core': {
  317. 'check_callback': true,
  318. "multiple": false,
  319. 'animation': 0,
  320. "data": window.documentCategory
  321. },
  322. "contextmenu": {
  323. show_at_node: false,
  324. select_node: false,
  325. 'items' : function(node) {
  326. var items = {
  327. "添加文档": {
  328. "separator_before": false,
  329. "separator_after": true,
  330. "_disabled": false,
  331. "label": "添加文档",
  332. "icon": "fa fa-plus",
  333. "action": function (data) {
  334. var inst = $.jstree.reference(data.reference),
  335. node = inst.get_node(data.reference);
  336. openCreateCatalogDialog(node);
  337. }
  338. },
  339. "编辑": {
  340. "separator_before": false,
  341. "separator_after": true,
  342. "_disabled": false,
  343. "label": "编辑",
  344. "icon": "fa fa-edit",
  345. "action": function (data) {
  346. var inst = $.jstree.reference(data.reference);
  347. var node = inst.get_node(data.reference);
  348. openEditCatalogDialog(node);
  349. }
  350. },
  351. "删除": {
  352. "separator_before": false,
  353. "separator_after": true,
  354. "_disabled": false,
  355. "label": "删除",
  356. "icon": "fa fa-trash-o",
  357. "action": function (data) {
  358. var inst = $.jstree.reference(data.reference);
  359. var node = inst.get_node(data.reference);
  360. openDeleteDocumentDialog(node);
  361. }
  362. },
  363. "unlock" : {
  364. "separator_before": false,
  365. "separator_after": true,
  366. "_disabled": false,
  367. "label": "解锁",
  368. "icon": "fa fa-unlock",
  369. "action": function (data) {
  370. var inst = $.jstree.reference(data.reference);
  371. var node = inst.get_node(data.reference);
  372. unLockDocumentAction(node);
  373. }
  374. },
  375. "lock" : {
  376. "separator_before": false,
  377. "separator_after": true,
  378. "_disabled": false,
  379. "label": "锁定",
  380. "icon": "fa fa-lock",
  381. "action": function (data) {
  382. var inst = $.jstree.reference(data.reference);
  383. var node = inst.get_node(data.reference);
  384. lockDocumentAction(node);
  385. }
  386. }
  387. };
  388. console.log(this.get_type(node));
  389. if(this.get_type(node) === "lock") {
  390. delete items.lock;
  391. }else{
  392. delete items.unlock;
  393. }
  394. return items;
  395. },
  396. }
  397. }).on('loaded.jstree', function () {
  398. window.treeCatalog = $(this).jstree();
  399. }).on('select_node.jstree', function (node, selected, event) {
  400. if ($("#markdown-save").hasClass('change')) {
  401. if (confirm("编辑内容未保存,需要保存吗?")) {
  402. saveDocument(false, function () {
  403. loadDocument(selected);
  404. });
  405. return true;
  406. }
  407. }
  408. loadDocument(selected);
  409. }).on("move_node.jstree", jstree_save);
  410. //对html进行预处理
  411. function firstfilter(str) {
  412. //处理一下html,忽略从WORD粘贴时特殊情况下尾部乱码
  413. if (/(<html[\s\S]*<\/html>)/gi.test(str)) {
  414. str = str.match(/(<html[\s\S]*<\/html>)/gi)[0];
  415. }
  416. //去掉头部描述
  417. return str.replace(/<head>[\s\S]*<\/head>/gi, "")
  418. //去掉注释
  419. .replace(/<!--[\s\S]*?-->/ig, "")
  420. //去掉隐藏元素
  421. .replace(/<([a-z0-9]*)[^>]*\s*display:none[\s\S]*?><\/\1>/gi, '');
  422. }
  423. //去除冗余属性和标签
  424. function filterPasteWord(str) {
  425. return str.replace(/[\t\r\n]+/g, ' ').replace(/<!--[\s\S]*?-->/ig, "")
  426. //转换图片
  427. .replace(/<v:shape [^>]*>[\s\S]*?.<\/v:shape>/gi,
  428. function (str) {
  429. //opera能自己解析出image所这里直接返回空
  430. if (!!window.opera && window.opera.version) {
  431. return '';
  432. }
  433. try {
  434. //有可能是bitmap占为图,无用,直接过滤掉,主要体现在粘贴excel表格中
  435. if (/Bitmap/i.test(str)) {
  436. return '';
  437. }
  438. var src = str.match(/src=\s*"([^"]*)"/i)[1];
  439. return '<img src="' + src + '" />';
  440. } catch (e) {
  441. return '';
  442. }
  443. })
  444. //针对wps添加的多余标签处理
  445. .replace(/<\/?div[^>]*>/g, '')
  446. .replace(/<\/?span[^>]*>/g, '')
  447. .replace(/<\/?font[^>]*>/g, '')
  448. .replace(/<\/?col[^>]*>/g, '')
  449. .replace(/<\/?(span|div|o:p|v:.*?|input|label)[\s\S]*?>/g, '')
  450. //去掉所有属性,需要保留单元格合并
  451. //.replace(/<([a-zA-Z]+)\s*[^><]*>/g, "<$1>")
  452. //去掉多余的属性
  453. .replace(/v:\w+=(["']?)[^'"]+\1/g, '')
  454. .replace(/<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|xml|meta|link|style|\w+:\w+)(?=[\s\/>]))[^>]*>/gi, "").replace(/<p [^>]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi, "<p><strong>$1</strong></p>")
  455. //去掉多余的属性
  456. .replace(/\s+(class|lang|align)\s*=\s*(['"]?)([\w-]+)\2/gi, '')
  457. //清除多余的font/span不能匹配&nbsp;有可能是空格
  458. .replace(/<(font|span)[^>]*>(\s*)<\/\1>/gi,
  459. function (a, b, c) {
  460. return c.replace(/[\t\r\n ]+/g, " ");
  461. })
  462. //去掉style属性
  463. .replace(/(<[a-z][^>]*)\sstyle=(["'])([^\2]*?)\2/gi, "$1")
  464. // 去除不带引号的属性
  465. .replace(/(class|border|cellspacing|MsoNormalTable|valign|width|center|&nbsp;|x:str|height|x:num|cellpadding)(=[^ \f\n\r\t\v>]*)?/g, "")
  466. // 去除多余空格
  467. .replace(/(\S+)(\s+)/g, function (match, p1, p2) {
  468. return p1 + ' ';
  469. })
  470. .replace(/(\s)(>|<)/g, function (match, p1, p2) {
  471. return p2;
  472. })
  473. //处理表格中的p标签
  474. .replace(/(<table[^>]*[\s\S]*?><\/table>)/gi, function (a) {
  475. //嵌套表格不处理
  476. if (a.match(/(<table>)/gi).length > 1) {
  477. return a
  478. }
  479. if (!/<thead>/i.test(a) && !/(rowspan|colspan)/i.test(a)) {
  480. //没有表头,将第一行作为表头
  481. //修复,当表格只有一行时,正则错误
  482. const firstrow = "<table><thead>" + a.match(/<tr>[\s\S]*?(<\/tr>)/i)[0] + "</thead>";
  483. a = a.replace(/<tr>[\s\S]*?(<\/tr>)/i, "")
  484. .replace(/<table>/, firstrow);
  485. } else if (/<thead>/i.test(a) && /(rowspan|colspan)/i.test(a)) {
  486. a=a.replace(/<thead>/, "");
  487. }
  488. return a.replace(/<\/p><p>/ig, "<br/>")
  489. .replace(/<\/?p[^>]*>/ig, '')
  490. //.replace(/<td><\/td>/ig,"<td>&nbsp;</td>")
  491. .replace(/<td>&nbsp;<\/td>/g, "<td></td>")
  492. });
  493. }
  494. //判断粘贴的内容是否来自office
  495. function isWordDocument(str) {
  496. return /(class="?Mso|style="[^"]*\bmso\-|w:WordDocument|<(v|o):|lang=)/ig.test(str) || /\"urn:schemas-microsoft-com:office:office/ig.test(str);
  497. }
  498. //excel表格处理
  499. function pasteClipboardHtml(html) {
  500. const startFramgmentStr = '<!--StartFragment-->';
  501. const endFragmentStr = '<!--EndFragment-->';
  502. const startFragmentIndex = html.indexOf(startFramgmentStr);
  503. const endFragmentIndex = html.lastIndexOf(endFragmentStr);
  504. if (startFragmentIndex > -1 && endFragmentIndex > -1) {
  505. html = html.slice(startFragmentIndex + startFramgmentStr.length, endFragmentIndex);
  506. }
  507. // Wrap with <tr> if html contains dangling <td> tags
  508. // Dangling <td> tag is that tag does not have <tr> as parent node.
  509. if (/<\/td>((?!<\/tr>)[\s\S])*$/i.test(html)) {
  510. html = '<tr>' + html + '</tr>';
  511. }
  512. // Wrap with <table> if html contains dangling <tr> tags
  513. // Dangling <tr> tag is that tag does not have <table> as parent node.
  514. if (/<\/tr>((?!<\/table>)[\s\S])*$/i.test(html)) {
  515. html = '<table>' + html + '</table>';
  516. }
  517. return html;
  518. }
  519. //将html转换为markdown
  520. function html2md(str) {
  521. var gfm = turndownPluginGfm.gfm;
  522. var turndownService = new TurndownService({
  523. headingStyle: 'atx',
  524. hr: '- - -',
  525. bulletListMarker: '-',
  526. codeBlockStyle: 'indented',
  527. fence: '```',
  528. emDelimiter: '_',
  529. strongDelimiter: '**'
  530. });
  531. turndownService.use(gfm);
  532. turndownService.keep(['sub', 'sup']);//保留标签
  533. str=firstfilter(str);
  534. //str=pasteClipboardHtml(str);
  535. str=filterPasteWord(str);
  536. return turndownService.turndown(str);
  537. }
  538. //将word转换的html转换为markdown,并插入编辑器
  539. $("#btnhtml2md").click(function (e) {
  540. e.preventDefault();
  541. if ($(this).hasClass("disabled"))
  542. return false;
  543. var str = $("#output").html();
  544. var cm = window.editor.cm;
  545. var cursor = cm.getCursor();
  546. var selection = cm.getSelection();
  547. cm.replaceSelection(html2md(str)+"\n\n");
  548. $("#btnhtml2md").removeClass("disabled");
  549. $("#word2md").modal('hide');
  550. cm.focus();
  551. });
  552. //粘贴Pastearea自动获得焦点
  553. $('#Pasteoffice').on('shown.bs.modal', function (event) {
  554. var modal = $(this);
  555. var form=modal.find("#Pasteofficeform");
  556. var renameInput =form.find("#Pastearea");
  557. //获得焦点时文本全选
  558. renameInput.focus(function () {
  559. this.select();
  560. });
  561. renameInput.focus();
  562. });
  563. //粘贴解析
  564. $("#Pastearea")[0].addEventListener('paste', function (e) {
  565. var clipboard = e.clipboardData;
  566. if (!(clipboard && clipboard.items)) {
  567. return;
  568. }
  569. for (var i = 0, len = clipboard.items.length; i < len; i++) {
  570. var item = clipboard.items[i];
  571. if (item.kind === "string" && item.type === "text/html") {
  572. item.getAsString(function (str) {
  573. if (/<img [^>]*src=['"]([^'"]+)[^>]*>/gi.test(str)) {
  574. layer.msg("粘贴的内容中包含有图片,建议使用word转markdown模块处理!");
  575. }
  576. var markdown = html2md(str);
  577. $("#officeoutmd").val(markdown);
  578. });
  579. }
  580. }
  581. });
  582. //解析html源码为markdown
  583. $("#HtmlToMarkdown").click(function (e) {
  584. e.preventDefault();
  585. var str = $("#Pastearea").val();
  586. var markdown = html2md(str);
  587. $("#officeoutmd").val(markdown);
  588. });
  589. //将html转换为markdown,并插入编辑器
  590. $("#office2md").click(function (e) {
  591. e.preventDefault();
  592. if ($(this).hasClass("disabled"))
  593. return false;
  594. var str = $("#officeoutmd").val();
  595. var cm = window.editor.cm;
  596. var cursor = cm.getCursor();
  597. var selection = cm.getSelection();
  598. cm.replaceSelection(str+"\n\n");
  599. $("#office2md").removeClass("disabled");
  600. $("#Pasteoffice").modal('hide');
  601. cm.focus();
  602. });
  603. /**
  604. * 打开文档模板
  605. */
  606. $("#documentTemplateModal").on("click", ".section>a[data-type]", function () {
  607. var $this = $(this).attr("data-type");
  608. var body = $("#template-" + $this).html();
  609. if (body) {
  610. window.isLoad = true;
  611. window.editor.clear();
  612. window.editor.insertValue(body);
  613. window.editor.setCursor({ line: 0, ch: 0 });
  614. resetEditorChanged(true);
  615. }
  616. $("#documentTemplateModal").modal('hide');
  617. });
  618. });