forked from hinesboy/mavonEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change default markdown css and hljs js css to option for users
- Loading branch information
Showing
5 changed files
with
103 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,45 +4,55 @@ | |
* @Email: [email protected] | ||
* @Filename: highlight.js | ||
* @Last modified by: chc | ||
* @Last modified time: 2017-11-23T17:22:52+08:00 | ||
* @Last modified time: 2017-11-24T19:55:22+08:00 | ||
* @License: MIT | ||
* @Copyright: 2017 | ||
*/ | ||
|
||
// import hljs from 'highlight.js-async-webpack' | ||
import hljsLangs from './hljs/lang.hljs.js' | ||
import { | ||
loadScript | ||
} from './extra-function.js' | ||
function highLightCode(str, callback) { | ||
function highLightCode(str, callback, hljsLangFuc, hljsFuc) { | ||
var hljs = window.hljs; | ||
if (!hljs) { | ||
console.warn('hljs parsing file is missing. mavon-editor will autoload https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js'); | ||
loadScript('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js', function() { | ||
_highLightCode(str, callback); | ||
if (typeof hljsFuc !== 'function') { | ||
console.warn('external_link.hljs_js is not a function, hljs can not load by mavon-editor, if you want to disabled this log, set external_link.hljs_js to function'); | ||
callback(str); | ||
return; | ||
} | ||
var url = hljsFuc(); | ||
console.warn('hljs parsing file is missing. mavon-editor will autoload', url); | ||
loadScript(url, function() { | ||
_highLightCode(str, callback, hljsLangFuc); | ||
}); | ||
} else { | ||
_highLightCode(str, callback); | ||
if (typeof hljsLangFuc === 'function') { | ||
_highLightCode(str, callback, hljsLangFuc); | ||
} else { | ||
console.warn('external_link.hljs_lang is not a function, hljs will not to work'); | ||
callback(str); | ||
} | ||
} | ||
} | ||
function _highLightCode(str, callback) { | ||
function _highLightCode(str, callback, hljsLangFuc) { | ||
var dom = document.createElement('div'); | ||
var hljs = window.hljs; | ||
dom.innerHTML = str; | ||
var pre_code = dom.querySelectorAll('pre > div.hljs > code'); | ||
if (pre_code && hljs) { | ||
if (pre_code && hljs && (typeof hljsLangFuc === 'function')) { | ||
var flag = 0; | ||
var cnt = 0; | ||
var i = 0; | ||
var deal = 0; | ||
var not_include_lang = {}; // these lang parse file need to be include. | ||
var url = ''; | ||
for (i = 0; i < pre_code.length; i++) { | ||
var lang = pre_code[i].className.toLowerCase(); | ||
if (lang.length > 0) { | ||
cnt = cnt + 1; | ||
// if this lang parse file missing | ||
if (!hljs.getLanguage(lang) && hljsLangs[lang]) { | ||
not_include_lang[lang] = 1; | ||
url = hljsLangFuc(lang); | ||
if (!hljs.getLanguage(lang) && !not_include_lang.hasOwnProperty(lang) && url.length > 0) { | ||
not_include_lang[lang] = url; | ||
} | ||
} | ||
} | ||
|
@@ -54,8 +64,7 @@ function _highLightCode(str, callback) { | |
} | ||
} | ||
for (i = 0; i < need_langs.length; i++) { | ||
var script = document.createElement('script'); | ||
var url = 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/' + need_langs[i] + '.min.js'; | ||
url = not_include_lang[need_langs[i]]; | ||
loadScript(url, function() { | ||
deal = deal + 1; | ||
if (deal === need_langs.length) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* @Email: [email protected] | ||
* @Filename: markdown.js | ||
* @Last modified by: chc | ||
* @Last modified time: 2017-11-23T17:21:36+08:00 | ||
* @Last modified time: 2017-11-24T19:34:03+08:00 | ||
* @License: MIT | ||
* @Copyright: 2017 | ||
*/ | ||
|
@@ -58,9 +58,9 @@ markdown.use(emoji) | |
.use(sup) | ||
.use(sub) | ||
.use(container) | ||
.use(container, 'hljs-left')/*align left */ | ||
.use(container, 'hljs-center')/*align center */ | ||
.use(container, 'hljs-right')/*align right */ | ||
.use(container, 'hljs-left') /* align left */ | ||
.use(container, 'hljs-center')/* align center */ | ||
.use(container, 'hljs-right')/* align right */ | ||
.use(deflist) | ||
.use(abbr) | ||
.use(footnote) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters