dragon-editor 4.0.2 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -64,10 +64,9 @@
|
|
|
64
64
|
|
|
65
65
|
<script setup>
|
|
66
66
|
import { useEditorStore } from "../../store/editor";
|
|
67
|
-
import { ref, computed, nextTick } from "vue";
|
|
67
|
+
import { ref, computed, nextTick, onMounted } from "vue";
|
|
68
68
|
import { onClickOutside } from "@vueuse/core";
|
|
69
69
|
import { _moveCodeBlockEvent, _codeBlockShiftEnterEvent, _codeBlockTabEvent, _normalPasteEvent } from "../../utils/event";
|
|
70
|
-
import { _highlightingCode } from "../../utils/data";
|
|
71
70
|
const editorStore = useEditorStore();
|
|
72
71
|
const props = defineProps({
|
|
73
72
|
data: { type: null, required: true },
|
|
@@ -161,11 +160,12 @@ function contentKeydownEvent(event) {
|
|
|
161
160
|
async function setLanguageEvent(lang) {
|
|
162
161
|
if ($content.value !== null) {
|
|
163
162
|
const textContent = $content.value.textContent;
|
|
163
|
+
const highlights = hljs.highlight(textContent, { language: lang });
|
|
164
164
|
const newData = JSON.parse(JSON.stringify(props.data));
|
|
165
165
|
isLanguageListActive.value = false;
|
|
166
166
|
abortEdit();
|
|
167
167
|
newData.language = lang;
|
|
168
|
-
newData.textContent =
|
|
168
|
+
newData.textContent = highlights.value;
|
|
169
169
|
emit("update", newData);
|
|
170
170
|
await nextTick();
|
|
171
171
|
setEdit();
|
|
@@ -174,8 +174,9 @@ async function setLanguageEvent(lang) {
|
|
|
174
174
|
function setStyleEvent() {
|
|
175
175
|
if ($content.value !== null) {
|
|
176
176
|
const textContent = $content.value.textContent;
|
|
177
|
+
const highlights = hljs.highlight(textContent, { language: props.data.language });
|
|
177
178
|
const newData = JSON.parse(JSON.stringify(props.data));
|
|
178
|
-
newData.textContent =
|
|
179
|
+
newData.textContent = highlights.value;
|
|
179
180
|
emit("update", newData);
|
|
180
181
|
}
|
|
181
182
|
}
|
|
@@ -188,4 +189,12 @@ onClickOutside(
|
|
|
188
189
|
ignore: [$btnLanguageList]
|
|
189
190
|
}
|
|
190
191
|
);
|
|
192
|
+
onMounted(() => {
|
|
193
|
+
if (window.hljs === void 0) {
|
|
194
|
+
const script = document.createElement("script");
|
|
195
|
+
script.src = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js";
|
|
196
|
+
script.async = true;
|
|
197
|
+
document.head.appendChild(script);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
191
200
|
</script>
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare function _highlightingCode(text: string, language: string): string;
|
|
2
1
|
export declare function _arrangementNodeList(list: Node[], cursorStartNode: Node | null, cursorStartNodeOffset: number, cursorEndNode: Node | null, cursorEndNodeOffset: number): {
|
|
3
2
|
list: Node[];
|
|
4
3
|
cursorStartNode: Node | null;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import hljs from "highlight.js";
|
|
2
1
|
import { _isStrictlyEqualArrays } from "./index.js";
|
|
3
|
-
export function _highlightingCode(text, language) {
|
|
4
|
-
return hljs.highlight(text, { language }).value;
|
|
5
|
-
}
|
|
6
2
|
export function _arrangementNodeList(list, cursorStartNode, cursorStartNodeOffset, cursorEndNode, cursorEndNodeOffset) {
|
|
7
3
|
const arrangementNodeList = [];
|
|
8
4
|
list.forEach((node) => {
|