Skip to content

Commit 3b07d7b

Browse files
committed
feat: switch to rich text with markdown support
BREAKING
1 parent 5fb31ea commit 3b07d7b

File tree

5 files changed

+229
-62
lines changed

5 files changed

+229
-62
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"highlight.js": "^11.8.0",
1515
"html2pdf.js": "0.10.1",
1616
"marked": "^5.1.1",
17+
"quill": "^2.0.0",
18+
"quill-delta-to-markdown": "^0.6.0",
19+
"quilljs-markdown": "^1.2.0",
1720
"vue": "^3.3.4"
1821
},
1922
"devDependencies": {

pnpm-lock.yaml

Lines changed: 80 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/editor-rich.vue

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<template>
2+
<div
3+
name=""
4+
ref="texteditor"
5+
autofocus="true"
6+
class="flex-1 w-full code-editor"
7+
id="editor"
8+
></div>
9+
</template>
10+
<script>
11+
import "quill/dist/quill.bubble.css";
12+
import "quilljs-markdown/dist/quilljs-markdown-common-style.css";
13+
14+
import Quill from "quill";
15+
import QuillMarkdown from "quilljs-markdown";
16+
import { onMounted, ref } from "vue";
17+
import { deltaToMarkdown } from "quill-delta-to-markdown";
18+
19+
export default {
20+
name: "EditorRich",
21+
emits: ["change"],
22+
setup(props, { emit }) {
23+
const texteditor = ref(null);
24+
let quill;
25+
onMounted(() => {
26+
quill = new Quill("#editor", {
27+
theme: "bubble",
28+
});
29+
30+
quill.on("text-change", () => {
31+
const markdownCode = deltaToMarkdown(quill.getContents().ops);
32+
emit("change", markdownCode);
33+
});
34+
35+
// enable markdown conversion
36+
new QuillMarkdown(quill, {});
37+
38+
if (texteditor.value) {
39+
const editor = texteditor.value.querySelector(".ql-editor");
40+
texteditor.value.addEventListener("click", (e) => {
41+
if (e.target.id != "editor") {
42+
return;
43+
}
44+
editor.focus();
45+
});
46+
editor.focus();
47+
}
48+
});
49+
50+
return {
51+
texteditor,
52+
};
53+
},
54+
};
55+
</script>

0 commit comments

Comments
 (0)