Browse Source

:white_check_mark: :bug:

Van 6 years ago
parent
commit
acdd891d83
5 changed files with 24 additions and 11 deletions
  1. 11 8
      __test__/markdown/lute.test.ts
  2. 1 1
      package.json
  3. 1 1
      src/index.ts
  4. 5 0
      src/ts/markdown/highlightRender.ts
  5. 6 1
      src/ts/markdown/md2html.ts

+ 11 - 8
__test__/markdown/lute.test.ts

@@ -6,13 +6,16 @@ const globalAny: any = global;
 
 it('MarkdownIt', () => {
     spec.forEach(async (item: any) => {
-        const result = globalAny.lute.markdown(item.markdown, {
-            gfm: false,
-            softBreak2HardBreak: false,
-            autoSpace: false,
-            fixTermTypo: false,
-            emoji: false,
-        })
-        expect(result).toBe(item.html)
+        const lute = globalAny.Lute.New()
+        lute.SetGFMAutoLink(false)
+        lute.SetGFMStrikethrough(false)
+        lute.SetGFMTable(false)
+        lute.SetGFMTaskListItem(false)
+        lute.SetSoftBreak2HardBreak(false)
+        lute.SetAutoSpace(false)
+        lute.SetFixTermTypo(false)
+        lute.SetEmoji(false)
+        const result = lute.MarkdownStr("", item.markdown)
+        expect(result[0]).toBe(item.html)
     })
 })

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "vditor",
-  "version": "1.8.4",
+  "version": "1.8.5",
   "cdn": "https://cdn.jsdelivr.net/npm",
   "description": "A markdown editor written in TypeScript",
   "author": " Vanessa <[email protected]> (http://vanessa.b3log.org)",

+ 1 - 1
src/index.ts

@@ -77,7 +77,7 @@ class Vditor {
             this.vditor.toolbar = toolbar;
         }
 
-        loadLuteJs().then(() => {
+        loadLuteJs(this.vditor).then(() => {
             if (this.vditor.toolbar.elements.preview || this.vditor.toolbar.elements.both) {
                 const preview = new Preview(this.vditor);
                 this.vditor.preview = preview;

+ 5 - 0
src/ts/markdown/highlightRender.ts

@@ -22,6 +22,11 @@ export const highlightRender = async (hljsStyle: string, enableHighlight: boolea
         "school-book", "shades-of-purple", "solarized-dark", "solarized-light", "sunburst", "tomorrow-night",
         "tomorrow-night-blue", "tomorrow-night-bright", "tomorrow-night-eighties", "vs", "vs2015", "xcode", "xt256"];
 
+    const codes = element.querySelectorAll(".vditor-reset pre code")
+    if (codes.length === 0) {
+        return
+    }
+
     if (hljsThemes.includes(hljsStyle)) {
         addStyle(`${CDN_PATH}/vditor/dist/js/highlight.js/styles/${hljsStyle}.css`,
             "vditorHljsStyle");

+ 6 - 1
src/ts/markdown/md2html.ts

@@ -2,7 +2,7 @@ import {CDN_PATH, VDITOR_VERSION} from "../constants";
 
 declare const Lute: ILute;
 
-export const loadLuteJs = () => {
+export const loadLuteJs = (vditor?: IVditor) => {
     const scriptElement = document.createElement("script");
     scriptElement.type = "text/javascript";
     // scriptElement.src = `http://localhost:9000/src/js/lute/lute.min.js`;
@@ -11,6 +11,11 @@ export const loadLuteJs = () => {
 
     return new Promise((resolve) => {
         scriptElement.onload = () => {
+            if (vditor && !vditor.lute) {
+                vditor.lute = Lute.New();
+                vditor.lute.PutEmojis(vditor.options.hint.emoji);
+                vditor.lute.SetEmojiSite(vditor.options.hint.emojiPath);
+            }
             resolve();
         };
     });