提交 c2bb5ffe 编写于 作者: 璃白.'s avatar 璃白. 🌻

fix

上级 4c9a941b
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
:id="'md_' + id" :id="'md_' + id"
> >
<markdown-header <markdown-header
:id="textareaId"
:ref="'md_header' + id" :ref="'md_header' + id"
:text.sync="text" :text.sync="text"
:selectionInfo.sync="selectionInfo" :selectionInfo.sync="selectionInfo"
...@@ -90,7 +91,7 @@ export default { ...@@ -90,7 +91,7 @@ export default {
// 初始化时赋值 // 初始化时赋值
value: { value: {
type: [String, Number], type: [String, Number],
default: "" default: " "
}, },
// 全屏时的z-index // 全屏时的z-index
zIndex: { zIndex: {
...@@ -102,6 +103,10 @@ export default { ...@@ -102,6 +103,10 @@ export default {
type: Number, type: Number,
default: 0 default: 0
}, },
preview: {
type: String,
default: ""
},
// 是否可以预览 // 是否可以预览
canPreview: { canPreview: {
type: Boolean, type: Boolean,
...@@ -182,6 +187,11 @@ export default { ...@@ -182,6 +187,11 @@ export default {
} }
} }
}, },
preview: {
handler: function(val) {
this.showPreview = val === "preview";
}
},
text: { text: {
immediate: true, immediate: true,
handler: function(val) { handler: function(val) {
...@@ -240,6 +250,7 @@ export default { ...@@ -240,6 +250,7 @@ export default {
`${url})\n` `${url})\n`
); );
_this.text = newText; _this.text = newText;
_this.$refs.mdUploadFile.value = "";
} }
}); });
this.fileList = []; this.fileList = [];
......
...@@ -133,24 +133,19 @@ export function initStyle({ ...@@ -133,24 +133,19 @@ export function initStyle({
if (codeTheme) { if (codeTheme) {
switch (codeTheme) { switch (codeTheme) {
case "dark": case "dark":
import("highlight.js/styles/dark.css"); import("@/assets/style/code/dark.css");
break;
case "github":
import("highlight.js/styles/github.css");
break;
case "idea":
import("highlight.js/styles/idea.css");
break; break;
case "light": case "light":
import("highlight.js/styles/lightfair.css"); import("@/assets/style/code/lightfair.css");
break; break;
case "monokai": case "atom-one-dark":
import("highlight.js/styles/monokai.css"); import("@/assets/style/code/atom-one-dark.css");
break; break;
default: default:
break; break;
} }
} else {
import("@/assets/style/code/lightfair.css");
} }
} }
......
/*
Atom One Dark by Daniel Gamage
Original One Dark Syntax theme from https://github.com/atom/one-dark-syntax
base: #282c34
mono-1: #abb2bf
mono-2: #818896
mono-3: #5c6370
hue-1: #56b6c2
hue-2: #61aeee
hue-3: #c678dd
hue-4: #98c379
hue-5: #e06c75
hue-5-2: #be5046
hue-6: #d19a66
hue-6-2: #e6c07b
*/
.md_preview {
.md_hljs {
color: #abb2bf;
background: #282c34;
}
.hljs-comment,
.hljs-quote {
color: #5c6370;
font-style: italic;
}
.hljs-doctag,
.hljs-keyword,
.hljs-formula {
color: #c678dd;
}
.hljs-section,
.hljs-name,
.hljs-selector-tag,
.hljs-deletion,
.hljs-subst {
color: #e06c75;
}
.hljs-literal {
color: #56b6c2;
}
.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute,
.hljs-meta .hljs-string {
color: #98c379;
}
.hljs-attr,
.hljs-variable,
.hljs-template-variable,
.hljs-type,
.hljs-selector-class,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-number {
color: #d19a66;
}
.hljs-symbol,
.hljs-bullet,
.hljs-link,
.hljs-meta,
.hljs-selector-id,
.hljs-title {
color: #61aeee;
}
.hljs-built_in,
.hljs-title.class_,
.hljs-class .hljs-title {
color: #e6c07b;
}
.hljs-emphasis {
font-style: italic;
}
.hljs-strong {
font-weight: bold;
}
.hljs-link {
text-decoration: underline;
}
}
/*
Dark style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
*/
.md_preview {
.md_hljs {
color: #ddd;
background: #444;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-section,
.hljs-link {
color: white;
}
.hljs-subst {
/* default */
}
.hljs-string,
.hljs-title,
.hljs-name,
.hljs-type,
.hljs-attribute,
.hljs-symbol,
.hljs-bullet,
.hljs-built_in,
.hljs-addition,
.hljs-variable,
.hljs-template-tag,
.hljs-template-variable {
color: #d88;
}
.hljs-comment,
.hljs-quote,
.hljs-deletion,
.hljs-meta {
color: #777;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-title,
.hljs-section,
.hljs-doctag,
.hljs-type,
.hljs-name,
.hljs-strong {
font-weight: bold;
}
.hljs-emphasis {
font-style: italic;
}
}
/*
Lightfair style (c) Tristian Kelly <tristian.kelly560@gmail.com>
*/
.md_preview {
.md_hljs {
color: #444;
background: var(--md-editor-code-bg-color);
}
.hljs-name {
color: #01a3a3;
}
.hljs-tag,
.hljs-meta {
color: #778899;
}
.hljs-subst {
/* default */
}
.hljs-comment {
color: #888888;
}
.hljs-keyword,
.hljs-attribute,
.hljs-selector-tag,
.hljs-meta .hljs-keyword,
.hljs-doctag,
.hljs-name {
font-weight: bold;
}
.hljs-type,
.hljs-string,
.hljs-number,
.hljs-selector-id,
.hljs-selector-class,
.hljs-quote,
.hljs-template-tag,
.hljs-deletion {
color: #4286f4;
}
.hljs-title,
.hljs-section {
color: #4286f4;
font-weight: bold;
}
.hljs-regexp,
.hljs-symbol,
.hljs-variable,
.hljs-template-variable,
.hljs-link,
.hljs-selector-attr,
.hljs-selector-pseudo {
color: #bc6060;
}
.hljs-literal {
color: #62bcbc;
}
.hljs-built_in,
.hljs-bullet,
.hljs-code,
.hljs-addition {
color: #25c6c6;
}
.hljs-meta .hljs-string {
color: #4d99bf;
}
.hljs-emphasis {
font-style: italic;
}
.hljs-strong {
font-weight: bold;
}
}
...@@ -27,7 +27,7 @@ textarea { ...@@ -27,7 +27,7 @@ textarea {
padding: 0; padding: 0;
} }
img { // img {
display: block; // display: block;
margin: 0; // margin: 0;
} // }
...@@ -240,19 +240,19 @@ ...@@ -240,19 +240,19 @@
padding: 8px; padding: 8px;
tab-size: 4; tab-size: 4;
code { code {
&.hljs { &.md_hljs {
padding: 0; padding: 0;
} }
} }
&:not(.hljs) { &:not(.md_hljs) {
background-color: var(--md-editor-code-bg-color); // background-color: var(--md-editor-code-bg-color);
} }
} }
} }
code { code {
border-radius: 4px; border-radius: 4px;
display: inline-block; display: inline-block;
background-color: var(--md-editor-code-bg-color); // background-color: var(--md-editor-code-bg-color);
padding: 2px 6px; padding: 2px 6px;
font-family: -apple-system, SF UI Text, Arial, PingFang SC, Hiragino Sans GB, font-family: -apple-system, SF UI Text, Arial, PingFang SC, Hiragino Sans GB,
Microsoft YaHei, WenQuanYi Micro Hei, sans-serif, SimHei, SimSun; Microsoft YaHei, WenQuanYi Micro Hei, sans-serif, SimHei, SimSun;
...@@ -480,7 +480,7 @@ p[align="center"] { ...@@ -480,7 +480,7 @@ p[align="center"] {
font-family: Consolas, Inconsolata, Courier, monospace; font-family: Consolas, Inconsolata, Courier, monospace;
font-size: 14px; font-size: 14px;
line-height: 22px; line-height: 22px;
color: #000; // color: #000;
} }
.md_preview code ol li div.hljs-ln-code, .md_preview code ol li div.hljs-ln-code,
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
</template> </template>
<script> <script>
import marked from "marked"; import marked from "marked";
import "highlight.js/styles/github.css";
export default { export default {
data() { data() {
return { return {
...@@ -30,10 +29,23 @@ export default { ...@@ -30,10 +29,23 @@ export default {
default: false default: false
} }
}, },
// mounted() { mounted() {
// this.resetMinHeight(); setTimeout(() => {
// }, this.resetMinHeight();
}, 0)
this.addClass();
},
updated() {
this.addClass();
},
methods: { methods: {
addClass() {
setTimeout(() => {
const previewDom = document.querySelector(".md_preview code");
if (!previewDom) return;
previewDom.className = "md_hljs";
}, 0);
},
transferMarkdown(val) { transferMarkdown(val) {
marked.setOptions({ marked.setOptions({
highlight: function(code, lang, callback) { highlight: function(code, lang, callback) {
......
...@@ -83,6 +83,8 @@ export default { ...@@ -83,6 +83,8 @@ export default {
text: { text: {
immediate: true, immediate: true,
handler: function(val) { handler: function(val) {
const cursorPoint = getPosition(this.id);
console.log(cursorPoint);
this.textContent = val; this.textContent = val;
} }
}, },
......
...@@ -34,11 +34,15 @@ ...@@ -34,11 +34,15 @@
</div> </div>
</template> </template>
<script> <script>
import { isNotFalse, formatText } from "@/assets/js/utils"; import { isNotFalse, formatText, getPosition } from "@/assets/js/utils";
import toolButton from "./tool-button"; import toolButton from "./tool-button";
export default { export default {
components: { toolButton }, components: { toolButton },
props: { props: {
id: {
type: String,
default: ""
},
fullScreen: { fullScreen: {
type: Boolean, type: Boolean,
default: false default: false
...@@ -98,6 +102,9 @@ export default { ...@@ -98,6 +102,9 @@ export default {
this.toolButtonList.push(this.fullScreenBtn); this.toolButtonList.push(this.fullScreenBtn);
} }
} }
},
text: {
handler: function(newVal, oldVal) {}
} }
}, },
data() { data() {
...@@ -200,20 +207,32 @@ export default { ...@@ -200,20 +207,32 @@ export default {
const originalText = this.text; const originalText = this.text;
const selectionInfo = this.selectionInfo; const selectionInfo = this.selectionInfo;
const newText = formatText(originalText, selectionInfo, startStr, endStr); const newText = formatText(originalText, selectionInfo, startStr, endStr);
this.updateText(newText); const len = newText.length - originalText.length;
// const len = 0;
// this.$refs.tool_button.tab(); this.updateText(newText, len);
}, },
setShowPreview(val) { setShowPreview(val) {
this.$emit("update:showPreview", val); this.$emit("update:showPreview", val);
}, },
updateText(val) { updateText(val, len = 0) {
console.log(val);
this.$emit("update:text", val); this.$emit("update:text", val);
const cursorPoint = getPosition(this.id);
console.log(cursorPoint);
this.$emit("update:selectionInfo", { this.$emit("update:selectionInfo", {
selectorId: "", selectorId: "",
selectionStart: "", selectionStart: cursorPoint,
selectionEnd: "" selectionEnd: cursorPoint
}); });
console.log(cursorPoint);
setTimeout(() => {
// document.getElementById(this.id).setSelectionRange(0, 0);
document
.getElementById(this.id)
.setSelectionRange(cursorPoint + len, cursorPoint + len);
}, 0);
} }
} }
}; };
......
...@@ -53,6 +53,7 @@ function initMdEditor(obj) { ...@@ -53,6 +53,7 @@ function initMdEditor(obj) {
placeholder, placeholder,
maxLength, maxLength,
zIndex, zIndex,
preview: "",
focus: false, focus: false,
showWordLimit showWordLimit
}; };
...@@ -60,6 +61,7 @@ function initMdEditor(obj) { ...@@ -60,6 +61,7 @@ function initMdEditor(obj) {
change(val) { change(val) {
onChange(val); onChange(val);
_this.value = val; _this.value = val;
props.value = val.text;
}, },
input(val) { input(val) {
onInput(val); onInput(val);
...@@ -78,11 +80,13 @@ function initMdEditor(obj) { ...@@ -78,11 +80,13 @@ function initMdEditor(obj) {
onBlur(val); onBlur(val);
_this.value = val; _this.value = val;
props.focus = false; props.focus = false;
props.value = val.text;
_this.vEl.$forceUpdate(); _this.vEl.$forceUpdate();
}, },
submit(val) { submit(val) {
onSubmit(val); onSubmit(val);
_this.value = val; _this.value = val;
props.value = val.text;
}, },
upload({ val, callback }) { upload({ val, callback }) {
onUpload(val, function(res) { onUpload(val, function(res) {
...@@ -119,6 +123,15 @@ function initMdEditor(obj) { ...@@ -119,6 +123,15 @@ function initMdEditor(obj) {
props.focus = false; props.focus = false;
this.vEl.$forceUpdate(); this.vEl.$forceUpdate();
}; };
this.toggleTab = function(tabName) {
if (!tabName) {
props.preview = props.preview === "edit" ? "preview" : "edit";
} else {
props.preview = tabName;
}
this.vEl.$forceUpdate();
};
} }
window.MdEditor = initMdEditor; window.MdEditor = initMdEditor;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册