Repository: nhn/tui.editor
Pull request #2252 (2022-02-04 07:48:11)

fix: wrong `htmlBlock` converting
<!-- EDIT TITLE PLEASE -->
<!-- It should be one of them
  <ISSUE TYPE>: Short Description (<CLOSING TYPE> #<ISSUE NUMBERS>)
  ex)
  feat: add new feature (close #111)
  fix: wrong behavior (fix #111)
  chore: change build tool (ref #111)
-->

<!-- SPECIFY A ISSUE TYPE AT HEAD
  feat: A new feature
  fix: A bug fix
  docs: Documentation only changes
  style: Changes that do not affect the meaning of the code (white-space, formatting etc)
  refactor: A code change that neither fixes a bug or adds a feature
  perf: A code change that improves performance
  test: Adding missing tests
  chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
-->

<!-- ADD CLOSING TYPE AND ISSUE NUMBER AT TAIL
  (<CLOSING TYPE> #<ISSUE NUMBERS>)
  close: resolve not a bug(feature, docs, etc) completely
  fix: resolve a bug completely
  ref: not fully resolved or related to
-->

### Please check if the PR fulfills these requirements
- [x] It's the right issue type on the title
- [ ] When resolving a specific issue, it's referenced in the PR's title (e.g. `fix #xxx[,#xxx]`, where "xxx" is the issue number)
- [x] The commit message follows our guidelines
- [x] Tests for the changes have been added (for bug fixes/features)
- [ ] Docs have been added/updated (for bug fixes/features)
- [ ] It does not introduce a breaking change or has a description of the breaking change

### Description
* related issue(#1862)


---
Thank you for your contribution to TOAST UI product. 🎉 😘 ✨



Patch:
diff --git a/apps/editor/src/convertors/toMarkdown/toMdNodeTypeWriters.ts b/apps/editor/src/convertors/toMarkdown/toMdNodeTypeWriters.ts
index 963d3210..bd4fb453 100644
--- a/apps/editor/src/convertors/toMarkdown/toMdNodeTypeWriters.ts
+++ b/apps/editor/src/convertors/toMarkdown/toMdNodeTypeWriters.ts
@@ -225,8 +225,12 @@ export const nodeTypeWriters: ToMdNodeTypeWriterMap = {
     state.write(text);
   },
 
-  html(state, _, { text }) {
+  html(state, { node }, { text }) {
     state.write(text);
+
+    if (node.attrs.htmlBlock) {
+      state.closeBlock(node);
+    }
   },
 };
 
diff --git a/apps/editor/src/wysiwyg/nodes/html.ts b/apps/editor/src/wysiwyg/nodes/html.ts
index d6a7eb1e..6cf16c9f 100644
--- a/apps/editor/src/wysiwyg/nodes/html.ts
+++ b/apps/editor/src/wysiwyg/nodes/html.ts
@@ -14,7 +14,7 @@ import { reHTMLTag, ATTRIBUTE } from '@/utils/constants';
 
 export function getChildrenHTML(node: MdNode, typeName: string) {
   return node
-    .literal!.replace(new RegExp(`(<\\s*${typeName}[^>]+?>)|(</${typeName}\\s*[>])`, 'ig'), '')
+    .literal!.replace(new RegExp(`(<\\s*${typeName}[^>]*>)|(</${typeName}\\s*[>])`, 'ig'), '')
     .trim();
 }
 


Test patch:
diff --git a/apps/editor/src/__test__/unit/convertor.spec.ts b/apps/editor/src/__test__/unit/convertor.spec.ts
index de38c415..a86a6fe5 100644
--- a/apps/editor/src/__test__/unit/convertor.spec.ts
+++ b/apps/editor/src/__test__/unit/convertor.spec.ts
@@ -944,8 +944,27 @@ describe('Convertor', () => {
       assertConverting(markdown, expected);
     });
 
+    it('should convert html block node as the block node through inserting the blank line', () => {
+      const markdown = source`
+        para1
+
+        <iframe src="https://www.youtube.com/embed/XyenY12fzAk" width="420" height="315"></iframe>
+
+        para2
+      `;
+      const expected = source`
+        para1
+
+        <iframe height="315" width="420" src="https://www.youtube.com/embed/XyenY12fzAk"></iframe>
+
+        para2
+      `;
+
+      assertConverting(markdown, expected);
+    });
+
     it('should convert html inline node', () => {
-      const markdown = '<big class="my-big">content</big>';
+      const markdown = 'inline <big class="my-big">content</big>';
 
       assertConverting(markdown, markdown);
     });