fix: update code style

* 统一代码风格
* 修复超链接问题
* 新增待办列表
This commit is contained in:
yanglbme 2020-06-25 17:20:37 +08:00
parent 1f07dd39c6
commit cecd7dde55
17 changed files with 1010 additions and 969 deletions

View File

@ -43,6 +43,9 @@ Markdown 文档自动即时渲染为微信图文,让你不再为微信文章
- [x] 支持自定义 CSS 样式并实时渲染 - [x] 支持自定义 CSS 样式并实时渲染
- [x] 支持一键恢复至默认内容及样式 - [x] 支持一键恢复至默认内容及样式
- [x] 支持打开或关闭引用链接的选项 - [x] 支持打开或关闭引用链接的选项
- [ ] 新建右键点击菜单栏
- [ ] 插入表格功能优化
![select-and-change-color-theme](https://imgkr.cn-bj.ufileos.com/32c05c23-6309-491f-bd0d-f22a62c944b4.gif) ![select-and-change-color-theme](https://imgkr.cn-bj.ufileos.com/32c05c23-6309-491f-bd0d-f22a62c944b4.gif)

View File

@ -4,11 +4,18 @@
padding: 0; padding: 0;
} }
input, button, textarea { input,
button,
textarea {
font-family: inherit; font-family: inherit;
} }
h1, h2, h3, h4, h5, h6 { h1,
h2,
h3,
h4,
h5,
h6 {
font-weight: normal; font-weight: normal;
} }
@ -16,7 +23,8 @@ em {
font-style: normal !important; font-style: normal !important;
} }
html, body { html,
body {
height: 100%; height: 100%;
font-family: 'PingFang SC', BlinkMacSystemFont, Roboto, 'Helvetica Neue', sans-serif; font-family: 'PingFang SC', BlinkMacSystemFont, Roboto, 'Helvetica Neue', sans-serif;
} }
@ -112,6 +120,7 @@ section {
display: table; display: table;
width: 100% !important; width: 100% !important;
} }
/* /*
.preview table tr:nth-child(even){ .preview table tr:nth-child(even){
background: rgb(250, 250, 250); background: rgb(250, 250, 250);
@ -146,7 +155,8 @@ section {
} }
/*wechat code block*/ /*wechat code block*/
.rich_media_content .code-snippet *, .rich_media_content .code-snippet__fix * { .rich_media_content .code-snippet *,
.rich_media_content .code-snippet__fix * {
max-width: 1000% !important; max-width: 1000% !important;
} }
@ -156,7 +166,7 @@ section {
margin: 10px 8px; margin: 10px 8px;
color: #333; color: #333;
position: relative; position: relative;
background-color: rgb(238,238,238); background-color: rgb(238, 238, 238);
border: 1px solid #f0f0f0; border: 1px solid #f0f0f0;
border-radius: 2px; border-radius: 2px;
display: flex; display: flex;
@ -228,7 +238,8 @@ section {
outline: none; outline: none;
} }
.CodeMirror-scroll, .preview-wrapper { .CodeMirror-scroll,
.preview-wrapper {
overflow: unset; overflow: unset;
overflow-y: scroll; overflow-y: scroll;
} }

View File

@ -14,91 +14,111 @@
font-size: 16px; font-size: 16px;
padding: 20px; padding: 20px;
line-height: 25px; line-height: 25px;
} }
.cm-s-style-mirror div.CodeMirror-selected {
.cm-s-style-mirror div.CodeMirror-selected {
background: #e0e0e0; background: #e0e0e0;
} }
.cm-s-style-mirror .CodeMirror-line::selection,
.cm-s-style-mirror .CodeMirror-line > span::selection, .cm-s-style-mirror .CodeMirror-line::selection,
.cm-s-style-mirror .CodeMirror-line > span > span::selection { .cm-s-style-mirror .CodeMirror-line>span::selection,
.cm-s-style-mirror .CodeMirror-line>span>span::selection {
background: #e0e0e0; background: #e0e0e0;
} }
.cm-s-style-mirror .CodeMirror-line::-moz-selection,
.cm-s-style-mirror .CodeMirror-line > span::-moz-selection, .cm-s-style-mirror .CodeMirror-line::-moz-selection,
.cm-s-style-mirror .CodeMirror-line > span > span::-moz-selection { .cm-s-style-mirror .CodeMirror-line>span::-moz-selection,
.cm-s-style-mirror .CodeMirror-line>span>span::-moz-selection {
background: #e0e0e0; background: #e0e0e0;
} }
.cm-s-style-mirror .CodeMirror-gutters {
.cm-s-style-mirror .CodeMirror-gutters {
background: #f5f5f5; background: #f5f5f5;
border-right: 0px; border-right: 0px;
} }
.cm-s-style-mirror .CodeMirror-guttermarker {
.cm-s-style-mirror .CodeMirror-guttermarker {
color: #ac4142; color: #ac4142;
} }
.cm-s-style-mirror .CodeMirror-guttermarker-subtle {
.cm-s-style-mirror .CodeMirror-guttermarker-subtle {
color: #b0b0b0; color: #b0b0b0;
} }
.cm-s-style-mirror .CodeMirror-linenumber {
.cm-s-style-mirror .CodeMirror-linenumber {
color: #b0b0b0; color: #b0b0b0;
} }
.cm-s-style-mirror .CodeMirror-cursor {
.cm-s-style-mirror .CodeMirror-cursor {
border-left: 1px solid #505050; border-left: 1px solid #505050;
} }
.cm-s-style-mirror span.cm-comment { .cm-s-style-mirror span.cm-comment {
color:green; color: green;
} }
.cm-s-style-mirror span.cm-atom {
color: #aa759f;
}
.cm-s-style-mirror span.cm-number {
color: #aa759f;
}
.cm-s-style-mirror span.cm-property, .cm-s-style-mirror span.cm-atom {
.cm-s-style-mirror span.cm-attribute { color: #aa759f;
}
.cm-s-style-mirror span.cm-number {
color: #aa759f;
}
.cm-s-style-mirror span.cm-property,
.cm-s-style-mirror span.cm-attribute {
color: #90a959; color: #90a959;
} }
.cm-s-style-mirror span.cm-keyword {
.cm-s-style-mirror span.cm-keyword {
color: #023a52; color: #023a52;
} }
.cm-s-style-mirror span.cm-string {
color: #e46918;
}
.cm-s-style-mirror span.cm-variable { .cm-s-style-mirror span.cm-string {
color: #e46918;
}
.cm-s-style-mirror span.cm-variable {
color: #90a959; color: #90a959;
} }
.cm-s-style-mirror span.cm-variable-2 {
.cm-s-style-mirror span.cm-variable-2 {
color: #00695f; color: #00695f;
} }
.cm-s-style-mirror span.cm-variable-3 {
.cm-s-style-mirror span.cm-variable-3 {
color: #2e6e8a; color: #2e6e8a;
} }
.cm-s-style-mirror span.cm-def {
.cm-s-style-mirror span.cm-def {
color: #d28445; color: #d28445;
} }
.cm-s-style-mirror span.cm-bracket {
.cm-s-style-mirror span.cm-bracket {
color: #202020; color: #202020;
} }
.cm-s-style-mirror span.cm-tag {
color:#000; .cm-s-style-mirror span.cm-tag {
} color: #000;
.cm-s-style-mirror span.cm-link { }
.cm-s-style-mirror span.cm-link {
color: #b26a00; color: #b26a00;
} }
.cm-s-style-mirror span.cm-error {
.cm-s-style-mirror span.cm-error {
/* background: #ac4142; /* background: #ac4142;
color: #f5f5f5; */ color: #f5f5f5; */
text-decoration: underline; text-decoration: underline;
text-decoration-style: wavy; text-decoration-style: wavy;
text-decoration-color: #df8d8e; text-decoration-color: #df8d8e;
} }
.cm-s-style-mirror .CodeMirror-activeline-background {
background: #dddcdc;
}
.cm-s-style-mirror .CodeMirror-matchingbracket {
color: rgb(32,32,32) !important;
background-color: rgba(0,0,0,0.1) !important;
}
.cm-s-style-mirror .CodeMirror-activeline-background {
background: #dddcdc;
}
.cm-s-style-mirror .CodeMirror-matchingbracket {
color: rgb(32, 32, 32) !important;
background-color: rgba(0, 0, 0, 0.1) !important;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -1,32 +1,4 @@
<!DOCTYPE html> <!DOCTYPE html>
<!--
_.._ ,------------.
,' `. ( 你终于发现我啦 )
/ __) __` \ `-,----------'
( (`-`(-') ) _.-'
/) \ = / (
/' |--' . \
( ,---| `-.)__`
)( `-.,--' _`-.
'/,' ( Uu",
(_ , `/,-' )
`.__, : `-'/ /`--'
| `--' |
` `-._ /
\ (
/\ . \.
/ |` \ ,-\
/ \| .) / \
( ,'|\ ,' :
| \,`.`--"/ }
`,' \ |,' /
/ "-._ `-/ |
"-. "-.,'| ;
/ _/["---'""]
: / |"- '
' | /
` |
-->
<html lang="en"> <html lang="en">
<head> <head>
@ -38,7 +10,8 @@
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>微信 Markdown 编辑器</title> <title>微信 Markdown 编辑器</title>
<link rel="shortcut icon" href="https://imgkr.cn-bj.ufileos.com/f3accc83-b854-4e99-afb5-8a6465e1d84f.png"> <link rel="shortcut icon" href="https://imgkr.cn-bj.ufileos.com/f3accc83-b854-4e99-afb5-8a6465e1d84f.png">
<link rel="apple-touch-icon-precomposed" href="https://imgkr.cn-bj.ufileos.com/f3accc83-b854-4e99-afb5-8a6465e1d84f.png"> <link rel="apple-touch-icon-precomposed"
href="https://imgkr.cn-bj.ufileos.com/f3accc83-b854-4e99-afb5-8a6465e1d84f.png">
<link rel="stylesheet" href="assets/css/loading.css"> <link rel="stylesheet" href="assets/css/loading.css">
<link rel="stylesheet" href="libs/css/index.css"> <link rel="stylesheet" href="libs/css/index.css">
<link rel="stylesheet" href="libs/css/code-themes/github-v2.min.css"> <link rel="stylesheet" href="libs/css/code-themes/github-v2.min.css">
@ -48,7 +21,7 @@
</head> </head>
<body> <body>
<div id="app" > <div id="app">
</div> </div>
</body> </body>

View File

@ -7,9 +7,9 @@
margin: 0; margin: 0;
padding: 2px; padding: 2px;
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2); -webkit-box-shadow: 2px 3px 5px rgba(0, 0, 0, .2);
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2); -moz-box-shadow: 2px 3px 5px rgba(0, 0, 0, .2);
box-shadow: 2px 3px 5px rgba(0,0,0,.2); box-shadow: 2px 3px 5px rgba(0, 0, 0, .2);
border-radius: 3px; border-radius: 3px;
border: 1px solid silver; border: 1px solid silver;

View File

@ -14,91 +14,111 @@
font-size: 16px; font-size: 16px;
padding: 20px; padding: 20px;
line-height: 25px; line-height: 25px;
} }
.cm-s-style-mirror div.CodeMirror-selected {
.cm-s-style-mirror div.CodeMirror-selected {
background: #e0e0e0; background: #e0e0e0;
} }
.cm-s-style-mirror .CodeMirror-line::selection,
.cm-s-style-mirror .CodeMirror-line > span::selection, .cm-s-style-mirror .CodeMirror-line::selection,
.cm-s-style-mirror .CodeMirror-line > span > span::selection { .cm-s-style-mirror .CodeMirror-line>span::selection,
.cm-s-style-mirror .CodeMirror-line>span>span::selection {
background: #e0e0e0; background: #e0e0e0;
} }
.cm-s-style-mirror .CodeMirror-line::-moz-selection,
.cm-s-style-mirror .CodeMirror-line > span::-moz-selection, .cm-s-style-mirror .CodeMirror-line::-moz-selection,
.cm-s-style-mirror .CodeMirror-line > span > span::-moz-selection { .cm-s-style-mirror .CodeMirror-line>span::-moz-selection,
.cm-s-style-mirror .CodeMirror-line>span>span::-moz-selection {
background: #e0e0e0; background: #e0e0e0;
} }
.cm-s-style-mirror .CodeMirror-gutters {
.cm-s-style-mirror .CodeMirror-gutters {
background: #f5f5f5; background: #f5f5f5;
border-right: 0px; border-right: 0px;
} }
.cm-s-style-mirror .CodeMirror-guttermarker {
.cm-s-style-mirror .CodeMirror-guttermarker {
color: #ac4142; color: #ac4142;
} }
.cm-s-style-mirror .CodeMirror-guttermarker-subtle {
.cm-s-style-mirror .CodeMirror-guttermarker-subtle {
color: #b0b0b0; color: #b0b0b0;
} }
.cm-s-style-mirror .CodeMirror-linenumber {
.cm-s-style-mirror .CodeMirror-linenumber {
color: #b0b0b0; color: #b0b0b0;
} }
.cm-s-style-mirror .CodeMirror-cursor {
.cm-s-style-mirror .CodeMirror-cursor {
border-left: 1px solid #505050; border-left: 1px solid #505050;
} }
.cm-s-style-mirror span.cm-comment { .cm-s-style-mirror span.cm-comment {
color:green; color: green;
} }
.cm-s-style-mirror span.cm-atom {
color: #aa759f;
}
.cm-s-style-mirror span.cm-number {
color: #aa759f;
}
.cm-s-style-mirror span.cm-property, .cm-s-style-mirror span.cm-atom {
.cm-s-style-mirror span.cm-attribute { color: #aa759f;
}
.cm-s-style-mirror span.cm-number {
color: #aa759f;
}
.cm-s-style-mirror span.cm-property,
.cm-s-style-mirror span.cm-attribute {
color: #90a959; color: #90a959;
} }
.cm-s-style-mirror span.cm-keyword {
.cm-s-style-mirror span.cm-keyword {
color: #023a52; color: #023a52;
} }
.cm-s-style-mirror span.cm-string {
color: #e46918;
}
.cm-s-style-mirror span.cm-variable { .cm-s-style-mirror span.cm-string {
color: #e46918;
}
.cm-s-style-mirror span.cm-variable {
color: #90a959; color: #90a959;
} }
.cm-s-style-mirror span.cm-variable-2 {
.cm-s-style-mirror span.cm-variable-2 {
color: #00695f; color: #00695f;
} }
.cm-s-style-mirror span.cm-variable-3 {
.cm-s-style-mirror span.cm-variable-3 {
color: #2e6e8a; color: #2e6e8a;
} }
.cm-s-style-mirror span.cm-def {
.cm-s-style-mirror span.cm-def {
color: #d28445; color: #d28445;
} }
.cm-s-style-mirror span.cm-bracket {
.cm-s-style-mirror span.cm-bracket {
color: #202020; color: #202020;
} }
.cm-s-style-mirror span.cm-tag {
color:#000; .cm-s-style-mirror span.cm-tag {
} color: #000;
.cm-s-style-mirror span.cm-link { }
.cm-s-style-mirror span.cm-link {
color: #b26a00; color: #b26a00;
} }
.cm-s-style-mirror span.cm-error {
.cm-s-style-mirror span.cm-error {
/* background: #ac4142; /* background: #ac4142;
color: #f5f5f5; */ color: #f5f5f5; */
text-decoration: underline; text-decoration: underline;
text-decoration-style: wavy; text-decoration-style: wavy;
text-decoration-color: #df8d8e; text-decoration-color: #df8d8e;
} }
.cm-s-style-mirror .CodeMirror-activeline-background {
background: #dddcdc;
}
.cm-s-style-mirror .CodeMirror-matchingbracket {
color: rgb(32,32,32) !important;
background-color: rgba(0,0,0,0.1) !important;
}
.cm-s-style-mirror .CodeMirror-activeline-background {
background: #dddcdc;
}
.cm-s-style-mirror .CodeMirror-matchingbracket {
color: rgb(32, 32, 32) !important;
background-color: rgba(0, 0, 0, 0.1) !important;
}

View File

@ -8,9 +8,10 @@
</template> </template>
<script> <script>
export default { export default {
}
}
</script> </script>
<style scoped> <style scoped>

View File

@ -1,7 +1,7 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/LICENSE // Distributed under an MIT license: https://codemirror.net/LICENSE
import CodeMirror from "codemirror/lib/codemirror"; import CodeMirror from "codemirror/lib/codemirror";
(function(CodeMirror) { (function (CodeMirror) {
var defaults = { var defaults = {
pairs: "()[]{}''\"\"", pairs: "()[]{}''\"\"",
closeBefore: ")]}'\":;>", closeBefore: ")]}'\":;>",
@ -11,7 +11,7 @@ import CodeMirror from "codemirror/lib/codemirror";
var Pos = CodeMirror.Pos; var Pos = CodeMirror.Pos;
CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) { CodeMirror.defineOption("autoCloseBrackets", false, function (cm, val, old) {
if (old && old != CodeMirror.Init) { if (old && old != CodeMirror.Init) {
cm.removeKeyMap(keyMap); cm.removeKeyMap(keyMap);
cm.state.closeBrackets = null; cm.state.closeBrackets = null;
@ -29,7 +29,11 @@ import CodeMirror from "codemirror/lib/codemirror";
return defaults[name]; return defaults[name];
} }
var keyMap = { Backspace: handleBackspace, Enter: handleEnter }; var keyMap = {
Backspace: handleBackspace,
Enter: handleEnter
};
function ensureBound(chars) { function ensureBound(chars) {
for (var i = 0; i < chars.length; i++) { for (var i = 0; i < chars.length; i++) {
var ch = chars.charAt(i), var ch = chars.charAt(i),
@ -40,7 +44,7 @@ import CodeMirror from "codemirror/lib/codemirror";
ensureBound(defaults.pairs + "`"); ensureBound(defaults.pairs + "`");
function handler(ch) { function handler(ch) {
return function(cm) { return function (cm) {
return handleChar(cm, ch); return handleChar(cm, ch);
}; };
} }
@ -85,7 +89,7 @@ import CodeMirror from "codemirror/lib/codemirror";
var around = charsAround(cm, ranges[i].head); var around = charsAround(cm, ranges[i].head);
if (!around || explode.indexOf(around) % 2 != 0) return CodeMirror.Pass; if (!around || explode.indexOf(around) % 2 != 0) return CodeMirror.Pass;
} }
cm.operation(function() { cm.operation(function () {
var linesep = cm.lineSeparator() || "\n"; var linesep = cm.lineSeparator() || "\n";
cm.replaceSelection(linesep + linesep, null); cm.replaceSelection(linesep + linesep, null);
cm.execCommand("goCharLeft"); cm.execCommand("goCharLeft");
@ -174,7 +178,7 @@ import CodeMirror from "codemirror/lib/codemirror";
var left = pos % 2 ? pairs.charAt(pos - 1) : ch; var left = pos % 2 ? pairs.charAt(pos - 1) : ch;
var right = pos % 2 ? ch : pairs.charAt(pos + 1); var right = pos % 2 ? ch : pairs.charAt(pos + 1);
cm.operation(function() { cm.operation(function () {
if (type == "skip") { if (type == "skip") {
cm.execCommand("goCharRight"); cm.execCommand("goCharRight");
} else if (type == "skipThree") { } else if (type == "skipThree") {

View File

@ -1,6 +1,5 @@
export default { export default {
builtinFonts: [ builtinFonts: [{
{
label: '无衬线', label: '无衬线',
value: '-apple-system-font,BlinkMacSystemFont, Helvetica Neue, PingFang SC, Hiragino Sans GB , Microsoft YaHei UI , Microsoft YaHei ,Arial,sans-serif' value: '-apple-system-font,BlinkMacSystemFont, Helvetica Neue, PingFang SC, Hiragino Sans GB , Microsoft YaHei UI , Microsoft YaHei ,Arial,sans-serif'
}, },
@ -9,8 +8,7 @@ export default {
value: "Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif" value: "Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif"
} }
], ],
sizeOption: [ sizeOption: [{
{
label: '12px', label: '12px',
value: '12px', value: '12px',
desc: '更小' desc: '更小'
@ -36,8 +34,7 @@ export default {
desc: '更大' desc: '更大'
} }
], ],
colorOption: [ colorOption: [{
{
label: '经典蓝', label: '经典蓝',
value: 'rgba(15, 76, 129, 1)', value: 'rgba(15, 76, 129, 1)',
hex: '最新流行' hex: '最新流行'

View File

@ -18,8 +18,7 @@ export function solveHtml(nightMode = false) {
let html = element.innerHTML let html = element.innerHTML
let res = ""; let res = "";
res = juice.inlineContent( res = juice.inlineContent(
html, html, {
{
inlinePseudoElements: true, inlinePseudoElements: true,
preserveImportant: true preserveImportant: true
} }

View File

@ -10,13 +10,16 @@ import CodeMirror from "codemirror/lib/codemirror";
// Comment/uncomment the specified range // Comment/uncomment the specified range
CodeMirror.defineExtension('commentRange', function (isComment, from, to) { CodeMirror.defineExtension('commentRange', function (isComment, from, to) {
var cm = this; var curMode = CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(from).state).mode var cm = this;
var curMode = CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(from).state).mode
cm.operation(function () { cm.operation(function () {
if (isComment) { // Comment range if (isComment) { // Comment range
cm.replaceRange(curMode.commentEnd, to) cm.replaceRange(curMode.commentEnd, to)
cm.replaceRange(curMode.commentStart, from) cm.replaceRange(curMode.commentStart, from)
if (from.line == to.line && from.ch == to.ch) // An empty comment inserted - put cursor inside 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) } {
cm.setCursor(from.line, from.ch + curMode.commentStart.length)
}
} else { // Uncomment range } else { // Uncomment range
var selText = cm.getRange(from, to) var selText = cm.getRange(from, to)
var startIndex = selText.indexOf(curMode.commentStart) var startIndex = selText.indexOf(curMode.commentStart)
@ -47,12 +50,16 @@ import CodeMirror from "codemirror/lib/codemirror";
// Applies automatic formatting to the specified range // Applies automatic formatting to the specified range
CodeMirror.defineExtension('autoFormatRange', function (from, to) { CodeMirror.defineExtension('autoFormatRange', function (from, to) {
var cm = this var cm = this
var outer = cm.getMode(); var text = cm.getRange(from, to).split('\n') var outer = cm.getMode();
var text = cm.getRange(from, to).split('\n')
var state = CodeMirror.copyState(outer, cm.getTokenAt(from).state) var state = CodeMirror.copyState(outer, cm.getTokenAt(from).state)
var tabSize = cm.getOption('tabSize') var tabSize = cm.getOption('tabSize')
var out = ''; var lines = 0; var atSol = from.ch == 0 var out = '';
function newline () { var lines = 0;
var atSol = from.ch == 0
function newline() {
out += '\n' out += '\n'
atSol = true atSol = true
++lines ++lines
@ -62,14 +69,17 @@ import CodeMirror from "codemirror/lib/codemirror";
var stream = new CodeMirror.StringStream(text[i], tabSize) var stream = new CodeMirror.StringStream(text[i], tabSize)
while (!stream.eol()) { while (!stream.eol()) {
var inner = CodeMirror.innerMode(outer, state) var inner = CodeMirror.innerMode(outer, state)
var style = outer.token(stream, state); var cur = stream.current() var style = outer.token(stream, state);
var cur = stream.current()
stream.start = stream.pos stream.start = stream.pos
if (!atSol || /\S/.test(cur)) { if (!atSol || /\S/.test(cur)) {
out += cur out += cur
atSol = false atSol = false
} }
if (!atSol && inner.mode.newlineAfterToken && if (!atSol && inner.mode.newlineAfterToken &&
inner.mode.newlineAfterToken(style, cur, stream.string.slice(stream.pos) || text[i + 1] || '', inner.state)) { newline() } 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 (!stream.pos && outer.blankLine) outer.blankLine(state)
if (!atSol) newline() if (!atSol) newline()
@ -77,7 +87,9 @@ import CodeMirror from "codemirror/lib/codemirror";
cm.operation(function () { cm.operation(function () {
cm.replaceRange(out, from, to) cm.replaceRange(out, from, to)
for (var cur = from.line + 1, end = from.line + lines; cur <= end; ++cur) { cm.indentLine(cur, 'smart') } for (var cur = from.line + 1, end = from.line + lines; cur <= end; ++cur) {
cm.indentLine(cur, 'smart')
}
cm.setSelection(from, cm.getCursor(false)) cm.setSelection(from, cm.getCursor(false))
}) })
}) })

View File

@ -4,7 +4,7 @@ import prettierMarkdown from 'prettier/parser-markdown'
// 设置自定义颜色 // 设置自定义颜色
export function setColorWithTemplate (template) { export function setColorWithTemplate(template) {
return function (color) { return function (color) {
let custom_theme = JSON.parse(JSON.stringify(template)) let custom_theme = JSON.parse(JSON.stringify(template))
custom_theme.block.h1['border-bottom'] = `2px solid ${color}` custom_theme.block.h1['border-bottom'] = `2px solid ${color}`
@ -16,7 +16,7 @@ export function setColorWithTemplate (template) {
} }
} }
export const setColorWithCustomTemplate = function setColorWithCustomTemplate ( export const setColorWithCustomTemplate = function setColorWithCustomTemplate(
template, template,
color color
) { ) {
@ -30,7 +30,7 @@ export const setColorWithCustomTemplate = function setColorWithCustomTemplate (
} }
// 设置自定义字体大小 // 设置自定义字体大小
export function setFontSizeWithTemplate (template) { export function setFontSizeWithTemplate(template) {
return function (fontSize) { return function (fontSize) {
let custom_theme = JSON.parse(JSON.stringify(template)) let custom_theme = JSON.parse(JSON.stringify(template))
custom_theme.block.h1['font-size'] = `${fontSize * 1.14}px` custom_theme.block.h1['font-size'] = `${fontSize * 1.14}px`
@ -44,7 +44,7 @@ export function setFontSizeWithTemplate (template) {
export const setColor = setColorWithTemplate(default_theme) export const setColor = setColorWithTemplate(default_theme)
export const setFontSize = setFontSizeWithTemplate(default_theme) export const setFontSize = setFontSizeWithTemplate(default_theme)
export function customCssWithTemplate (jsonString, color, theme) { export function customCssWithTemplate(jsonString, color, theme) {
let custom_theme = JSON.parse(JSON.stringify(theme)) let custom_theme = JSON.parse(JSON.stringify(theme))
// block // block
custom_theme.block.h1['border-bottom'] = `2px solid ${color}` custom_theme.block.h1['border-bottom'] = `2px solid ${color}`
@ -97,8 +97,9 @@ export function customCssWithTemplate (jsonString, color, theme) {
* *
* @param {css字符串} css * @param {css字符串} css
*/ */
export function css2json (css) { export function css2json(css) {
// 移除CSS所有注释 // 移除CSS所有注释
let open, close;
while ( while (
(open = css.indexOf('/*')) !== -1 && (open = css.indexOf('/*')) !== -1 &&
(close = css.indexOf('*/')) !== -1 (close = css.indexOf('*/')) !== -1
@ -120,7 +121,7 @@ export function css2json (css) {
// `{"font": "'Times New Roman' 1em", "color": "#ff0000", "margin-top": "1em"}` // `{"font": "'Times New Roman' 1em", "color": "#ff0000", "margin-top": "1em"}`
// 辅助方法将array转为object // 辅助方法将array转为object
function toObject (array) { function toObject(array) {
let ret = {} let ret = {}
array.forEach(e => { array.forEach(e => {
const index = e.indexOf(':') const index = e.indexOf(':')