diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..350ab51 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +*.js +*.vue \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js index 3e7e7d0..49c2e6d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,7 +10,8 @@ module.exports = { rules: { 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', - 'camelcase': 'off' + 'camelcase': 'off', + 'eqeqeq': 'off' }, parserOptions: { parser: 'babel-eslint' diff --git a/public/assets/scripts/sync-scroll.js b/public/assets/scripts/sync-scroll.js index c9e31bb..c2f1231 100644 --- a/public/assets/scripts/sync-scroll.js +++ b/public/assets/scripts/sync-scroll.js @@ -1,23 +1,23 @@ // 左右栏同步滚动 $(document).ready(() => { - let timeout; - $('div.CodeMirror-scroll, #preview').on("scroll", function callback() { - clearTimeout(timeout); + let timeout + $('div.CodeMirror-scroll, #preview').on('scroll', function callback () { + clearTimeout(timeout) - let source = $(this), - target = $(source.is("#preview") ? 'div.CodeMirror-scroll' : '#preview'); + let source = $(this) + let target = $(source.is('#preview') ? 'div.CodeMirror-scroll' : '#preview') - target.off("scroll"); + target.off('scroll') - let source0 = source[0]; - let target0 = target[0]; + let source0 = source[0] + let target0 = target[0] - let percentage = source0.scrollTop / (source0.scrollHeight - source0.offsetHeight); - let height = percentage * (target0.scrollHeight - target0.offsetHeight); - target0.scrollTo(0, height); + let percentage = source0.scrollTop / (source0.scrollHeight - source0.offsetHeight) + let height = percentage * (target0.scrollHeight - target0.offsetHeight) + target0.scrollTo(0, height) timeout = setTimeout(() => { - target.on("scroll", callback); - }, 100); - }); -}); + target.on('scroll', callback) + }, 100) + }) +}) diff --git a/public/assets/scripts/themes/default-theme.js b/public/assets/scripts/themes/default-theme.js index c58c587..a17e20b 100644 --- a/public/assets/scripts/themes/default-theme.js +++ b/public/assets/scripts/themes/default-theme.js @@ -1,177 +1,177 @@ -let default_theme = { - BASE: { - 'text-align': 'left', - 'color': '#3f3f3f', - 'line-height': '1.75', +export const default_theme = { + BASE: { + 'text-align': 'left', + 'color': '#3f3f3f', + 'line-height': '1.75' + }, + BASE_BLOCK: { + 'margin': '1em 8px' + }, + block: { + // 一级标题样式 + h1: { + 'font-size': '1.2em', + 'text-align': 'center', + 'font-weight': 'bold', + 'display': 'table', + 'margin': '2em auto 1em', + 'padding': '0 1em', + 'border-bottom': '2px solid rgba(0, 152, 116, 0.9)' }, - BASE_BLOCK: { - 'margin': '1em 8px' + + // 二级标题样式 + h2: { + 'font-size': '1.2em', + 'text-align': 'center', + 'font-weight': 'bold', + 'display': 'table', + 'margin': '4em auto 2em', + 'padding': '0 0.2em', + 'background': 'rgba(0, 152, 116, 0.9)', + 'color': '#fff' }, - block: { - // 一级标题样式 - h1: { - 'font-size': '1.2em', - 'text-align': 'center', - 'font-weight': 'bold', - 'display': 'table', - 'margin': '2em auto 1em', - 'padding': '0 1em', - 'border-bottom': '2px solid rgba(0, 152, 116, 0.9)' - }, - // 二级标题样式 - h2: { - 'font-size': '1.2em', - 'text-align': 'center', - 'font-weight': 'bold', - 'display': 'table', - 'margin': '4em auto 2em', - 'padding': '0 0.2em', - 'background': 'rgba(0, 152, 116, 0.9)', - 'color': '#fff' - }, - - // 三级标题样式 - h3: { - 'font-weight': 'bold', - 'font-size': '1.1em', - 'margin': '2em 8px 0.75em 0', - 'line-height': '1.2', - 'padding-left': '8px', - 'border-left': '3px solid rgba(0, 152, 116, 0.9)' - }, - - // 四级标题样式 - h4: { - 'font-weight': 'bold', - 'font-size': '1em', - 'margin': '2em 8px 0.5em', - 'color': 'rgba(66, 185, 131, 0.9)' - }, - - // 段落样式 - p: { - 'margin': '1.5em 8px', - 'letter-spacing': '0.1em' - }, - - // 引用样式 - blockquote: { - 'font-style': 'normal', - 'border-left': 'none', - 'padding': '1em', - 'border-radius': '4px', - 'color': '#FEEEED', - 'background': 'rgba(27,31,35,.05)', - 'margin': '2em 8px' - }, - - blockquote_p: { - 'letter-spacing': '0.1em', - 'color': 'rgb(80, 80, 80)', - 'font-family': 'PingFangSC-light, PingFangTC-light, Open Sans, Helvetica Neue, sans-serif', - 'font-size': '1em', - 'display': 'inline', - }, - - code: { - 'font-size': '80%', - 'overflow': 'auto', - 'color': '#333', - 'background': 'rgb(247, 247, 247)', - 'border-radius': '2px', - 'padding': '10px', - 'line-height': '1.5', - 'border': '1px solid rgb(236,236,236)', - 'margin': '20px 0', - }, - - image: { - 'border-radius': '4px', - 'display': 'block', - 'margin': '0.1em auto 0.5em', - 'width': '100% !important', - }, - - image_org: { - 'border-radius': '4px', - 'display': 'block' - }, - - ol: { - 'margin-left': '0', - 'padding-left': '1em' - }, - - ul: { - 'margin-left': '0', - 'padding-left': '1em', - 'list-style': 'circle' - }, - - footnotes: { - 'margin': '0.5em 8px', - 'font-size': '80%' - }, - - figure: { - 'margin': '1.5em 8px', - } + // 三级标题样式 + h3: { + 'font-weight': 'bold', + 'font-size': '1.1em', + 'margin': '2em 8px 0.75em 0', + 'line-height': '1.2', + 'padding-left': '8px', + 'border-left': '3px solid rgba(0, 152, 116, 0.9)' }, - inline: { - listitem: { - 'text-indent': '-1em', - 'display': 'block', - 'margin': '0.2em 8px' - }, - codespan: { - 'font-size': '90%', - 'color': '#d14', - 'background': 'rgba(27,31,35,.05)', - 'padding': '3px 5px', - 'border-radius': '4px', - }, + // 四级标题样式 + h4: { + 'font-weight': 'bold', + 'font-size': '1em', + 'margin': '2em 8px 0.5em', + 'color': 'rgba(66, 185, 131, 0.9)' + }, - link: { - 'color': '#576b95' - }, + // 段落样式 + p: { + 'margin': '1.5em 8px', + 'letter-spacing': '0.1em' + }, - wx_link: { - 'color': '#576b95', - 'text-decoration': 'none', - }, + // 引用样式 + blockquote: { + 'font-style': 'normal', + 'border-left': 'none', + 'padding': '1em', + 'border-radius': '4px', + 'color': '#FEEEED', + 'background': 'rgba(27,31,35,.05)', + 'margin': '2em 8px' + }, - // 字体加粗样式 - strong: { - 'color': 'rgba(15, 76, 129, 0.9)', - 'font-weight': 'bold', - }, + blockquote_p: { + 'letter-spacing': '0.1em', + 'color': 'rgb(80, 80, 80)', + 'font-family': 'PingFangSC-light, PingFangTC-light, Open Sans, Helvetica Neue, sans-serif', + 'font-size': '1em', + 'display': 'inline' + }, - table: { - 'border-collapse': 'collapse', - 'text-align': 'center', - 'margin': '1em 8px' - }, + code: { + 'font-size': '80%', + 'overflow': 'auto', + 'color': '#333', + 'background': 'rgb(247, 247, 247)', + 'border-radius': '2px', + 'padding': '10px', + 'line-height': '1.5', + 'border': '1px solid rgb(236,236,236)', + 'margin': '20px 0' + }, - thead: { - 'background': 'rgba(0, 0, 0, 0.05)', - 'font-weight': 'bold' - }, + image: { + 'border-radius': '4px', + 'display': 'block', + 'margin': '0.1em auto 0.5em', + 'width': '100% !important' + }, - td: { - 'border': '1px solid #dfdfdf', - 'padding': '0.25em 0.5em' - }, + image_org: { + 'border-radius': '4px', + 'display': 'block' + }, - footnote: { - 'font-size': '12px' - }, + ol: { + 'margin-left': '0', + 'padding-left': '1em' + }, - figcaption: { - 'text-align': 'center', - 'color': '#888', - 'font-size': '0.8em' - } + ul: { + 'margin-left': '0', + 'padding-left': '1em', + 'list-style': 'circle' + }, + + footnotes: { + 'margin': '0.5em 8px', + 'font-size': '80%' + }, + + figure: { + 'margin': '1.5em 8px' } -}; \ No newline at end of file + }, + inline: { + listitem: { + 'text-indent': '-1em', + 'display': 'block', + 'margin': '0.2em 8px' + }, + + codespan: { + 'font-size': '90%', + 'color': '#d14', + 'background': 'rgba(27,31,35,.05)', + 'padding': '3px 5px', + 'border-radius': '4px' + }, + + link: { + 'color': '#576b95' + }, + + wx_link: { + 'color': '#576b95', + 'text-decoration': 'none' + }, + + // 字体加粗样式 + strong: { + 'color': 'rgba(15, 76, 129, 0.9)', + 'font-weight': 'bold' + }, + + table: { + 'border-collapse': 'collapse', + 'text-align': 'center', + 'margin': '1em 8px' + }, + + thead: { + 'background': 'rgba(0, 0, 0, 0.05)', + 'font-weight': 'bold' + }, + + td: { + 'border': '1px solid #dfdfdf', + 'padding': '0.25em 0.5em' + }, + + footnote: { + 'font-size': '12px' + }, + + figcaption: { + 'text-align': 'center', + 'color': '#888', + 'font-size': '0.8em' + } + } +} diff --git a/public/index.html b/public/index.html index 5d50505..fdf725d 100644 --- a/public/index.html +++ b/public/index.html @@ -46,8 +46,8 @@ - - + + @@ -59,41 +59,21 @@ -
-
-
Loading...
-
-
-
- - - - - - - - - - - - - - + - diff --git a/src/assets/logo.png b/src/assets/logo.png deleted file mode 100644 index f3d2503..0000000 Binary files a/src/assets/logo.png and /dev/null differ diff --git a/src/components/CodemirrorEditor.vue b/src/components/CodemirrorEditor.vue new file mode 100644 index 0000000..d5cce96 --- /dev/null +++ b/src/components/CodemirrorEditor.vue @@ -0,0 +1,502 @@ + + + diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue index 428c117..0d5239c 100644 --- a/src/components/HelloWorld.vue +++ b/src/components/HelloWorld.vue @@ -1,59 +1,15 @@ - - diff --git a/src/components/Loading.vue b/src/components/Loading.vue new file mode 100644 index 0000000..da6502d --- /dev/null +++ b/src/components/Loading.vue @@ -0,0 +1,18 @@ + + + + + diff --git a/src/scripts/format.js b/src/scripts/format.js new file mode 100644 index 0000000..f9979f1 --- /dev/null +++ b/src/scripts/format.js @@ -0,0 +1,83 @@ +(function () { + CodeMirror.extendMode('css', { + commentStart: '/*', + commentEnd: '*/', + newlineAfterToken: function (type, content) { + return /^[;{}]$/.test(content) + } + }) + + // Comment/uncomment the specified range + CodeMirror.defineExtension('commentRange', function (isComment, from, to) { + var cm = this; var curMode = CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(from).state).mode + cm.operation(function () { + if (isComment) { // Comment range + cm.replaceRange(curMode.commentEnd, to) + cm.replaceRange(curMode.commentStart, from) + if (from.line == to.line && from.ch == to.ch) // An empty comment inserted - put cursor inside + { cm.setCursor(from.line, from.ch + curMode.commentStart.length) } + } else { // Uncomment range + var selText = cm.getRange(from, to) + var startIndex = selText.indexOf(curMode.commentStart) + var endIndex = selText.lastIndexOf(curMode.commentEnd) + if (startIndex > -1 && endIndex > -1 && endIndex > startIndex) { + // Take string till comment start + selText = selText.substr(0, startIndex) + + // From comment start till comment end + selText.substring(startIndex + curMode.commentStart.length, endIndex) + + // From comment end till string end + selText.substr(endIndex + curMode.commentEnd.length) + } + cm.replaceRange(selText, from, to) + } + }) + }) + + // Applies automatic mode-aware indentation to the specified range + CodeMirror.defineExtension('autoIndentRange', function (from, to) { + var cmInstance = this + this.operation(function () { + for (var i = from.line; i <= to.line; i++) { + cmInstance.indentLine(i, 'smart') + } + }) + }) + + // Applies automatic formatting to the specified range + CodeMirror.defineExtension('autoFormatRange', function (from, to) { + var cm = this + var outer = cm.getMode(); var text = cm.getRange(from, to).split('\n') + var state = CodeMirror.copyState(outer, cm.getTokenAt(from).state) + var tabSize = cm.getOption('tabSize') + + var out = ''; var lines = 0; var atSol = from.ch == 0 + function newline () { + out += '\n' + atSol = true + ++lines + } + + for (var i = 0; i < text.length; ++i) { + var stream = new CodeMirror.StringStream(text[i], tabSize) + while (!stream.eol()) { + var inner = CodeMirror.innerMode(outer, state) + var style = outer.token(stream, state); var cur = stream.current() + stream.start = stream.pos + if (!atSol || /\S/.test(cur)) { + out += cur + atSol = false + } + if (!atSol && inner.mode.newlineAfterToken && + inner.mode.newlineAfterToken(style, cur, stream.string.slice(stream.pos) || text[i + 1] || '', inner.state)) { newline() } + } + if (!stream.pos && outer.blankLine) outer.blankLine(state) + if (!atSol) newline() + } + + cm.operation(function () { + cm.replaceRange(out, from, to) + for (var cur = from.line + 1, end = from.line + lines; cur <= end; ++cur) { cm.indentLine(cur, 'smart') } + cm.setSelection(from, cm.getCursor(false)) + }) + }) +})() diff --git a/src/scripts/renderers/wx-renderer.js b/src/scripts/renderers/wx-renderer.js index bf0a1a8..118772a 100644 --- a/src/scripts/renderers/wx-renderer.js +++ b/src/scripts/renderers/wx-renderer.js @@ -1,3 +1,4 @@ +import marked from 'marked' const WxRenderer = function (opts) { this.opts = opts let ENV_STRETCH_IMAGE = true diff --git a/src/scripts/themes/default-theme.js b/src/scripts/themes/default-theme.js index c58c587..bb9c5ad 100644 --- a/src/scripts/themes/default-theme.js +++ b/src/scripts/themes/default-theme.js @@ -1,4 +1,4 @@ -let default_theme = { +export default { BASE: { 'text-align': 'left', 'color': '#3f3f3f', @@ -174,4 +174,4 @@ let default_theme = { 'font-size': '0.8em' } } -}; \ No newline at end of file +}; diff --git a/src/scripts/util.js b/src/scripts/util.js index 1dfdd25..6e49f14 100644 --- a/src/scripts/util.js +++ b/src/scripts/util.js @@ -1,3 +1,5 @@ +import default_theme from "./themes/default-theme"; + // 设置自定义颜色 export function setColorWithTemplate (template) { return function (color) { diff --git a/src/views/Home.vue b/src/views/Home.vue index fc2e940..02d9ab5 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,6 +1,5 @@ diff --git a/tests/unit/example.spec.js b/tests/unit/example.spec.js index f84fb39..71f5d50 100644 --- a/tests/unit/example.spec.js +++ b/tests/unit/example.spec.js @@ -2,11 +2,5 @@ import { shallowMount } from '@vue/test-utils' import HelloWorld from '@/components/HelloWorld.vue' describe('HelloWorld.vue', () => { - it('renders props.msg when passed', () => { - const msg = 'new message' - const wrapper = shallowMount(HelloWorld, { - propsData: { msg } - }) - expect(wrapper.text()).toMatch(msg) - }) + })