前幾個版本的地址:html
http://www.javashuo.com/article/p-bwzeewpi-dg.htmlgit
http://www.javashuo.com/article/p-ylgomgze-ck.htmlgithub
http://www.javashuo.com/article/p-uecqrztc-bv.html服務器
http://www.javashuo.com/article/p-ytfejgea-dm.htmlmarkdown
注意:使用本軟件前,需先在博客園後臺設置默認編輯器爲markdown編輯器
廢話少說,先上界面圖片:工具
10月25日,我發佈了博客園文章編輯器的4.0版本,獲得了不少朋友的支持,佈局
(後來我本身發現了一些問題,因而偷偷發了博客園文章編輯器的4.0.1版本,也沒通知你們,不過好在有自動升級功能)學習
當時有不少朋友問我,這個工具支持不支持markdown,3d
我以爲寫markdown的人仍是挺多的,
調查了博客園確實支持markdown編輯器,
並且我開發了markdown的編輯器,對於那些使用HTML富文本編輯器的用戶來講,也很容易上手,沒太大改變,
還能使他們經過個人編輯器學習一點markdown的語法知識,何樂而不爲呢?!
說實話,我確實低估了開發這個東西的難度
本打算到github上隨便拉一個來,
嵌到nwjs裏去就能夠了,
然而看了幾個高分項目,都不合我意。
(不過,說真心話仍是要感謝這些項目,我寫這個工具參考了不少這些開源項目的源碼)
我以爲這個項目最主要的難點是:
好在這些難點我都克服了
如今你看到的東西,就是這一陣子斷斷續續努力的成果
這裏羅列的是全部的我以爲重要的功能
開源地址:https://gitee.com/xland/cnblogs
下載地址:https://gitee.com/xland/cnblogs/releases
強烈但願你們能給個star;
這讓我知道你在用;
這讓我有動力繼續作一些對你們有用的東西;
第一段代碼是用於控制滾動條同步滾動的:
var editorScroll = function () { setTimeout(function () { if (rightScrolling) { return; } var scrollInfo = editor.getScrollInfo(); var lineNumber = editor.lineAtHeight(scrollInfo.top, 'local'); var range = editor.getRange({ line: 0, ch: null }, { line: lineNumber, ch: null }); var parser = new DOMParser(); var doc = parser.parseFromString(marked(range), 'text/html'); var topLineIndex = doc.body.querySelectorAll('p, h1, h2, h3, h4, h5, h6, li, pre, blockquote, hr, table').length; var eles = document.getElementById("right").querySelectorAll('p, h1, h2, h3, h4, h5, h6, li, pre, blockquote, hr, table'); var scTop = eles[topLineIndex].offsetTop; $(".right").scrollTop(scTop); }, 800) } editor.on("scroll", editorScroll);
第二段代碼,是用於插入markdown特有語法符號的
var wrapWidth = function (start, end) { if (!end) { end = start; } var arr = editor.doc.getSelections(); var result = []; arr.forEach(item => { var tempArr = item.split('\n'); for (var i = 0; i < tempArr.length; i++) { if (tempArr[i]) { tempArr[i] = start + tempArr[i] + end; } } result.push(tempArr.join('\n')); }) editor.doc.replaceSelections(result); };