Van 5 years ago
parent
commit
4a3dd4445f
4 changed files with 13 additions and 5 deletions
  1. 2 1
      CHANGELOG.md
  2. 3 2
      src/ts/toolbar/Record.ts
  3. 6 1
      src/ts/upload/index.ts
  4. 2 1
      src/ts/wysiwyg/processCodeRender.ts

+ 2 - 1
CHANGELOG.md

@@ -38,8 +38,9 @@
 * [3](https://github.com/Vanessa219/vditor/issues/3) 编辑预览同步滚动改进 `enhancement`
 * [4](https://github.com/Vanessa219/vditor/issues/4) 添加支持思维导图的功能 `enhancement`
 
-### v2.0.12 / 2020-01-06
+### v2.0.13 / 2020-01-06
 
+* [39](https://github.com/Vanessa219/vditor/issues/39) 所见即所得模式录音bug `修复缺陷`
 * [38](https://github.com/Vanessa219/vditor/issues/38) 有序列表顺序错误 `修复缺陷`
 * [37](https://github.com/Vanessa219/vditor/issues/37) 为 wysiwyg 代码块添加快捷键 `引入特性`
 * [36](https://github.com/Vanessa219/vditor/issues/36) two 'enter' at code block `修复缺陷`

+ 3 - 2
src/ts/toolbar/Record.ts

@@ -17,6 +17,7 @@ export class Record extends MenuItem {
         let mediaRecorder: MediaRecorder;
         this.element.children[0].addEventListener(getEventName(), (event) => {
             event.preventDefault();
+            const editorElement = vditor.currentMode === "wysiwyg" ? vditor.wysiwyg.element : vditor.editor.element
             if (!mediaRecorder) {
                 navigator.mediaDevices.getUserMedia({audio: true}).then((mediaStream: MediaStream) => {
                     mediaRecorder = new MediaRecorder(mediaStream);
@@ -33,7 +34,7 @@ export class Record extends MenuItem {
                     };
                     mediaRecorder.startRecordingNewWavFile();
                     vditor.tip.show(i18n[vditor.options.lang].recording);
-                    vditor.editor.element.setAttribute("contenteditable", "false");
+                    editorElement.setAttribute("contenteditable", "false");
                     this.element.children[0].classList.add("vditor-menu--current");
                 }).catch(() => {
                     vditor.tip.show(i18n[vditor.options.lang]["record-tip"]);
@@ -50,7 +51,7 @@ export class Record extends MenuItem {
                 this.element.children[0].classList.remove("vditor-menu--current");
             } else {
                 vditor.tip.show(i18n[vditor.options.lang].recording);
-                vditor.editor.element.setAttribute("contenteditable", "false");
+                editorElement.setAttribute("contenteditable", "false");
                 mediaRecorder.startRecordingNewWavFile();
                 this.element.children[0].classList.add("vditor-menu--current");
             }

+ 6 - 1
src/ts/upload/index.ts

@@ -106,7 +106,12 @@ const genUploadedLabel = (responseText: string, vditor: IVditor) => {
         const filename = vditor.options.upload.filename(key.substr(0, lastIndex)) + type;
         type = type.toLowerCase();
         if (type === ".wav" || type === ".mp3" || type === ".ogg") {
-            succFileText += `<audio controls="controls" src="${path}"></audio>\n`;
+            if (vditor.currentMode === "wysiwyg") {
+                succFileText += `<div class="vditor-wysiwyg__block" data-type="html-block"
+ data-block="0"><pre><code>&lt;audio controls="controls" src="${path}"&gt;&lt;/audio&gt;</code></pre>`;
+            } else {
+                succFileText += `<audio controls="controls" src="${path}"></audio>\n`;
+            }
         } else if (type === ".apng"
             || type === ".bmp"
             || type === ".gif"

+ 2 - 1
src/ts/wysiwyg/processCodeRender.ts

@@ -60,7 +60,8 @@ export const processCodeRender = (blockElement: HTMLElement, vditor: IVditor) =>
             codeRender(previewPanel, vditor.options.lang);
         }
     } else if (blockType.indexOf("html") > -1) {
-        previewPanel.innerHTML = innerHTML;
+        previewPanel.innerHTML = innerHTML.replace(/&amp;/g, "&")
+            .replace(/&lt;/g, "<") .replace(/&gt;/g, ">");
     } else if (blockType.indexOf("math") > -1) {
         previewPanel.innerHTML = `<${tagName} class="vditor-math">${innerHTML}</${tagName}>`;
         mathRenderByLute(previewPanel, vditor.options.cdn);