diff --git a/assets/scripts/editor.js b/assets/scripts/editor.js
index 3aa4e34..ac810d5 100644
--- a/assets/scripts/editor.js
+++ b/assets/scripts/editor.js
@@ -6,9 +6,9 @@ let app = new Vue({
output: '',
source: '',
editorThemes: [
- { label: '淡雅', value: 'xq-light'},
- { label: '精美', value: 'eclipse'},
- { label: '暗绿', value: 'oceanic-next'}
+ { label: '淡雅', value: 'xq-light' },
+ { label: '精美', value: 'eclipse' },
+ { label: '暗绿', value: 'oceanic-next' }
],
editor: null,
builtinFonts: [
@@ -28,8 +28,8 @@ let app = new Vue({
],
colorOption: [
{ label: '橘红', value: 'rgba(255, 95, 46, 0.9)', hex: '#FF5F2E' },
- { label: '淡绿', value: 'rgba(66, 185, 131, 0.9)', hex: '#42B983'},
- { label: '暗青', value: 'rgba(0, 139, 139, 0.9)', hex: '#008B8B'}
+ { label: '淡绿', value: 'rgba(66, 185, 131, 0.9)', hex: '#42B983' },
+ { label: '暗青', value: 'rgba(0, 139, 139, 0.9)', hex: '#008B8B' }
],
aboutDialogVisible: false
};
@@ -40,7 +40,6 @@ let app = new Vue({
return d;
},
mounted() {
- let self = this;
this.editor = CodeMirror.fromTextArea(
document.getElementById('editor'),
{
@@ -51,9 +50,9 @@ let app = new Vue({
mode: 'text/x-markdown',
}
);
- this.editor.on("change", function (cm, change) {
- self.refresh();
- self.saveEditorContent();
+ this.editor.on("change", (cm, change) => {
+ this.refresh();
+ this.saveEditorContent();
});
this.wxRenderer = new WxRenderer({
theme: setColor(this.currentColor),
@@ -67,13 +66,13 @@ let app = new Vue({
axios({
method: 'get',
url: './assets/default-content.md',
- }).then(function (resp) {
- self.editor.setValue(resp.data)
+ }).then(resp => {
+ this.editor.setValue(resp.data)
})
}
},
methods: {
- renderWeChat: function (source) {
+ renderWeChat(source) {
let output = marked(source, { renderer: this.wxRenderer.getRenderer() });
if (this.wxRenderer.hasFootnotes()) {
// 去除第一行的 margin-top
@@ -85,22 +84,22 @@ let app = new Vue({
}
return output
},
- editorThemeChanged: function (editorTheme) {
+ editorThemeChanged(editorTheme) {
this.editor.setOption('theme', editorTheme)
},
- fontChanged: function (fonts) {
+ fontChanged(fonts) {
this.wxRenderer.setOptions({
fonts: fonts
});
this.refresh()
},
- sizeChanged: function (size) {
+ sizeChanged(size) {
this.wxRenderer.setOptions({
size: size
});
this.refresh()
},
- colorChanged: function (color) {
+ colorChanged(color) {
let theme = setColor(color)
this.wxRenderer.setOptions({
theme: theme
@@ -108,19 +107,19 @@ let app = new Vue({
this.refresh()
},
// 刷新右侧预览
- refresh: function () {
+ refresh() {
this.output = this.renderWeChat(this.editor.getValue(0))
},
// 将左侧编辑器内容保存到 LocalStorage
- saveEditorContent: function () {
+ saveEditorContent() {
let content = this.editor.getValue(0);
- if (content){
+ if (content) {
localStorage.setItem("__editor_content", content);
} else {
localStorage.removeItem("__editor_content");
}
},
- copy: function () {
+ copy() {
let clipboardDiv = document.getElementById('output');
clipboardDiv.focus();
window.getSelection().removeAllRanges();
@@ -157,13 +156,13 @@ let app = new Vue({
});
}
},
- openWindow: function (url) {
+ openWindow(url) {
window.open(url);
}
},
- updated: function () {
- this.$nextTick(function () {
- prettyPrint()
+ updated() {
+ this.$nextTick(() => {
+ prettyPrint();
})
}
});
diff --git a/assets/scripts/renderers/wx-renderer.js b/assets/scripts/renderers/wx-renderer.js
index b9f1a44..87b6725 100644
--- a/assets/scripts/renderers/wx-renderer.js
+++ b/assets/scripts/renderers/wx-renderer.js
@@ -9,11 +9,9 @@ let WxRenderer = function (opts) {
let CODE_FONT_FAMILY = "Menlo, Operator Mono, Consolas, Monaco, monospace";
- let merge = function (base, extend) {
- return Object.assign({}, base, extend)
- };
+ let merge = (base, extend) => Object.assign({}, base, extend);
- this.buildTheme = function (themeTpl) {
+ this.buildTheme = themeTpl => {
let mapping = {};
let base = merge(themeTpl.BASE, {
'font-family': this.opts.fonts,
@@ -30,6 +28,7 @@ let WxRenderer = function (opts) {
mapping[ele] = merge(base, style)
}
}
+
for (let ele in themeTpl.block) {
if (themeTpl.block.hasOwnProperty(ele)) {
let style = themeTpl.block[ele];
@@ -42,7 +41,7 @@ let WxRenderer = function (opts) {
return mapping
};
- let getStyles = function (tokenName, addition) {
+ let getStyles = (tokenName, addition) => {
let arr = [];
let dict = styleMapping[tokenName];
if (!dict) return '';
@@ -52,14 +51,13 @@ let WxRenderer = function (opts) {
return `style="${arr.join(';') + (addition || '')}"`
};
- let addFootnote = function (title, link) {
- footnoteIndex += 1;
- footnotes.push([footnoteIndex, title, link]);
- return footnoteIndex
+ let addFootnote = (title, link) => {
+ footnotes.push([++footnoteIndex, title, link]);
+ return footnoteIndex;
};
- this.buildFootnotes = function () {
- let footnoteArray = footnotes.map(function (x) {
+ this.buildFootnotes = () => {
+ let footnoteArray = footnotes.map(x => {
if (x[1] === x[2]) {
return `[${x[0]}]
: ${x[1]}
`
}
@@ -68,31 +66,33 @@ let WxRenderer = function (opts) {
return `
${footnoteArray.join('\n')}
` }; - this.buildAddition = function () { - return '' - }; + this.buildAddition = () => { + return ` + + `; + } - this.setOptions = function (newOpts) { + this.setOptions = newOpts => { this.opts = merge(this.opts, newOpts) }; - this.hasFootnotes = function () { - return footnotes.length !== 0 - }; + this.hasFootnotes = () => footnotes.length !== 0; - this.getRenderer = function () { + this.getRenderer = () => { footnotes = []; footnoteIndex = 0; @@ -100,7 +100,7 @@ let WxRenderer = function (opts) { let renderer = new marked.Renderer(); FuriganaMD.register(renderer); - renderer.heading = function (text, level) { + renderer.heading = (text, level) => { switch (level) { case 1: return `${text}
` - }; - renderer.blockquote = function (text) { + renderer.paragraph = text => `${text}
`; + + renderer.blockquote = text => { text = text.replace(/`); return `
${text}` }; - renderer.code = function (text, infoString) { + renderer.code = (text, infoString) => { text = text.replace(//g, ">"); let lines = text.split('\n'); let codeLines = []; let numbers = []; + for (let i = 0; i < lines.length; i++) { const line = lines[i]; codeLines.push(`
${(line || '
')}
`);
numbers.push('')
}
let lang = infoString || '';
- return `` - + codeLines.join('') - + `
+ ${codeLines.join('')} ++
${text}
`
- };
- renderer.listitem = function (text) {
- return `<%s/>${text}`;
- };
- renderer.list = function (text, ordered, start) {
+ renderer.codespan = (text, infoString) => `${text}
`;
+ renderer.listitem = text => `<%s/>${text}`;
+
+ renderer.list = (text, ordered, start) => {
text = text.replace(/<\/*p.*?>/g, '');
let segments = text.split(`<%s/>`);
if (!ordered) {
@@ -157,7 +158,7 @@ let WxRenderer = function (opts) {
}
return `${text}
`; }; - renderer.image = function (href, title, text) { + renderer.image = (href, title, text) => { let subText = ''; if (text) { subText = `${text}
` - }; - renderer.table = function (header, body) { - return `${text}
`; + renderer.table = (header, body) => `