code style:
@@ -38,7 +38,12 @@ module.exports = {
return {
codeStyle: "github",
styles,
- code: '```' + code + '\n```'
+ code: '
A \n```' + code + '\n```',
+ xssOptions:{
+ whiteList: {
+ span: ['style']
+ }
+ }
};
}
}
diff --git a/src/lib/core/rules.js b/src/lib/core/rules.js
deleted file mode 100644
index 504a9d4b3..000000000
--- a/src/lib/core/rules.js
+++ /dev/null
@@ -1,34 +0,0 @@
-export const HEADER_FLAG = ' _MD-HEADER_ ';
-export const IMAGE_FLAG = ['_MD-HEADER_', true];
-const IMAGE_FLAG_STR = `${IMAGE_FLAG[0]}="${IMAGE_FLAG[1]}" `;
-
-export function headRule(defaultTocHeadRule) {
- return function (tokens, index) {
- let code = defaultTocHeadRule(tokens, index);
- var label = tokens[index + 1];
- if (label.type === 'inline') {
- return code.replace('
0) {
$vm.$_render(src, func, res);
@@ -126,10 +136,10 @@ export default {
var deal = 0;
for (var i = 0; i < needLangs.length; i++) {
var url = $vm.p_external_link.hljs_lang(needLangs[i]);
- loadScript(url, function() {
+ loadScript(url, function () {
deal = deal + 1;
if (deal === needLangs.length) {
- res = markdown.render(src);
+ res = this.MarkdownIt.render(src);
func(res);
}
})
@@ -137,7 +147,7 @@ export default {
}
},
watch: {
- ishljs: function(val) {
+ ishljs: function (val) {
hljs_opts.highlighted = val;
}
}
diff --git a/src/mavon-editor.vue b/src/mavon-editor.vue
index 5e2c8d876..52c3f0cb7 100644
--- a/src/mavon-editor.vue
+++ b/src/mavon-editor.vue
@@ -119,8 +119,6 @@ import md_toolbar_left from './components/md-toolbar-left.vue'
import md_toolbar_right from './components/md-toolbar-right.vue'
import "./lib/font/css/fontello.css"
import './lib/css/md.css'
-import { skipRule } from './lib/core/rules.js'
-import { FilterXSS } from 'xss';
export default {
mixins: [markdown],
@@ -199,6 +197,10 @@ export default {
return CONFIG.toolbars
}
},
+ html: {// Enable HTML tags in source
+ type: Boolean,
+ default: true
+ },
xssOptions: { // XSS 选项
type: [Object, Boolean],
default() {
@@ -643,65 +645,9 @@ export default {
console.warn('hljs color scheme', val, 'do not exist, hljs color scheme will not change');
}
},
- xssHandler(htmlCode) {
- if (this._xssHandler) {
- return this._xssHandler.process(htmlCode);
- }
-
- let originalTagFun;
- if (typeof this.xssOptions['onTag'] === 'function') {
- originalTagFun = this.xssOptions['onTag'];
- }
- this.xssOptions['onTag'] = function(tag, html, info) {
- let code = skipRule(tag, html);
- if (originalTagFun) {
- code = originalTagFun(tag,code);
- }
- if (html !== code) {
- return code;
- }
- }
-
- let originalTagAttr;
- if (typeof this.xssOptions['onTagAttr'] === 'function') {
- originalTagAttr = this.xssOptions['onTagAttr'];
- }
- this.xssOptions['onTagAttr'] = function (tag, name, value) {
- const whiteClass = {
- "div": ['hljs-left', 'hljs-center', 'hljs-right', 'hljs-*'],
- "code": ['lang-language','lang-*'],
- "span": ['hljs-*']
- };
-
- let newValue, oriValue;
- if (name === 'class' &&
- whiteClass[tag] &&
- whiteClass[tag].find(el => {
- return !!value.match(el)
- }))
- {
- newValue = name + '="' + value + '"';
- }
-
- if (originalTagAttr) {
- oriValue = originalTagAttr(tag, name, value);
- }
-
- if (newValue || oriValue) {
- return oriValue || newValue;
- }
- };
-
- this._xssHandler = new FilterXSS(this.xssOptions);
- return this._xssHandler.process(htmlCode);
- },
iRender(toggleChange) {
var $vm = this;
this.$render($vm.d_value, function(res) {
- // HTML 渲染前先进行过滤,避免 xss 问题,默认情况下开始此功能
- if (typeof $vm.xssOptions === 'object') {
- res = $vm.xssHandler(res);
- }
$vm.d_render = res;
// change回调 toggleChange == false 时候触发change回调
if (!toggleChange)