diff --git a/src/code/index.wc b/src/code/index.wc index ffbf5f5..184349a 100644 --- a/src/code/index.wc +++ b/src/code/index.wc @@ -2,6 +2,7 @@
${s}
`).join('') + this.__CODE__.innerHTML = txt + } + mounted() { + var txt = this.innerHTML || this.textContent + this.value = txt.replace(/^[\r\n]|\s{2,}$/g, '') + this.textContent = '' + this._cpFN = $.bind(this.__CP__, 'click', ev => { try { navigator.clipboard.writeText(this.value) @@ -180,18 +200,14 @@ export default class Code { watch() { switch (name) { - case 'content': - this.props.content = val - val = val - .replace(//g, '>') - .split('\n') - val = val.map(s => `${s}
`).join('') - this.__CODE__.innerHTML = val - this.removeAttribute('content') + case 'lang': + this.props.lang = val.toLowerCase() + this.__LANG__.textContent = this.props.lang break - default: + case 'value': + this.value = val + this.removeAttribute('value') break } } diff --git a/src/marked/index.js b/src/markd/core.js similarity index 96% rename from src/marked/index.js rename to src/markd/core.js index b2fb2c5..c9e09cd 100644 --- a/src/marked/index.js +++ b/src/markd/core.js @@ -826,48 +826,12 @@ Renderer.prototype.code = function(code, lang, escaped) { code = code .replace(/<script([^&]*?)>/g, '') - if (this.options.highlight) { - var out = this.options.highlight(code, lang) - if (out != null && out !== code) { - escaped = true - code = out - } - } //转义特殊字符 - code = escaped ? code : escape(code, true) - lang = this.options.langPrefix + escape(lang, true) + code = escape(code, true) + lang = escape(lang, true) - var codes = code.split('\n'), - ln = codes.length, - idx = 0, - output = '', - multiCom = false - - while (idx++ < ln) { - //处理多行注释 - if (!multiCom) { - if ( - /^\s*?$/.test(codes[idx - 1]) - ) { - multiCom = true - codes[idx - 1] += '' - } - } else { - if (!/<\/span>$/.test(codes[idx - 1])) { - codes[idx - 1] = - '' + codes[idx - 1] + '' - } else { - codes[idx - 1] = '' + codes[idx - 1] - multiCom = false - } - } - - output += '' + codes[idx - 1] + '\n
' //加\n为了避免空行时无法显示
- }
-
- return '' + output + '' + return '