diff --git a/apps/editor/src/js/convertor.js b/apps/editor/src/js/convertor.js
index 7367b76394..6124c31d45 100644
--- a/apps/editor/src/js/convertor.js
+++ b/apps/editor/src/js/convertor.js
@@ -19,6 +19,7 @@ const attribute = `(?:\\s+${attrName}(?:\\s*=\\s*${attrValue})?)*\\s*`;
const openingTag = `(\\\\<|<)([A-Za-z][A-Za-z0-9\\-]*${attribute})(\\/?>)`;
const HTML_TAG_RX = new RegExp(openingTag, 'g');
const FRONT_MATTER_RX = /^\s?\\-\\-\\-([\s\S]+?)\\-\\-\\-/;
+const NBSP_RX = / /g;
/**
* Class Convertor
@@ -180,7 +181,7 @@ class Convertor {
result[index] = line;
});
- return result.join('\n');
+ return result.join('\n').replace(NBSP_RX, ' ');
}
_removeNewlinesBeforeAfterAndBlockElement(markdown) {
diff --git a/apps/editor/src/js/mdPreview.js b/apps/editor/src/js/mdPreview.js
index c96bd8265e..21c87b55ef 100644
--- a/apps/editor/src/js/mdPreview.js
+++ b/apps/editor/src/js/mdPreview.js
@@ -166,14 +166,14 @@ class MarkdownPreview extends Preview {
startEl.insertAdjacentHTML('beforebegin', newHtml);
let el = startEl;
- while (el !== endEl) {
+ while (el && el !== endEl) {
const nextEl = el.nextElementSibling;
el.parentNode.removeChild(el);
removeOffsetInfoByNode(el);
el = nextEl;
}
- if (el.parentNode) {
+ if (el?.parentNode) {
domUtils.remove(el);
removeOffsetInfoByNode(el);
}
diff --git a/apps/editor/src/js/wysiwygEditor.js b/apps/editor/src/js/wysiwygEditor.js
index 419ba5e79f..8d052058d8 100644
--- a/apps/editor/src/js/wysiwygEditor.js
+++ b/apps/editor/src/js/wysiwygEditor.js
@@ -30,6 +30,7 @@ import KeyMapper from './keyMapper';
import WwTextObject from './wwTextObject';
import ComponentManager from './componentManager';
import CodeBlockGadget from './ui/codeBlockGadget';
+import htmlSanitizer from './htmlSanitizer';
const keyMapper = KeyMapper.getSharedInstance();
@@ -83,7 +84,8 @@ class WysiwygEditor {
leafNodeNames: {
HR: false
},
- allowedBlocks: this._sanitizer ? [] : ['details', 'summary']
+ allowedBlocks:
+ this._sanitizer && this._sanitizer === htmlSanitizer ? [] : ['details', 'summary']
});
this.editor.blockCommandShortcuts();
diff --git a/apps/editor/test/unit/convertor.spec.js b/apps/editor/test/unit/convertor.spec.js
index 9c997acd1f..4ee69a53dd 100644
--- a/apps/editor/test/unit/convertor.spec.js
+++ b/apps/editor/test/unit/convertor.spec.js
@@ -744,3 +744,22 @@ describe('Convertor', () => {
});
});
});
+
+describe('Convertor without default sanitizer', () => {
+ let convertor, em;
+
+ beforeEach(() => {
+ em = new EventManager();
+ convertor = new Convertor(em);
+ convertor.initHtmlSanitizer(html => html);
+ });
+
+ it('should convert details block without default sanitizer', () => {
+ const markdown = '2021
test ';
+ const html =
+ '2021
test \n';
+
+ expect(convertor.toHTML(markdown)).toBe(html);
+ expect(convertor.toMarkdown(html)).toBe(markdown);
+ });
+});
diff --git a/apps/editor/test/unit/wysiwygEditor.spec.js b/apps/editor/test/unit/wysiwygEditor.spec.js
index 9dd58e4c55..914a91cb10 100644
--- a/apps/editor/test/unit/wysiwygEditor.spec.js
+++ b/apps/editor/test/unit/wysiwygEditor.spec.js
@@ -753,4 +753,13 @@ describe('WysiwygEditor', () => {
it('getSanitizer()', () => {
expect(wwe.getSanitizer()).toEqual(sanitizer);
});
+
+ it('should render details block without default sanitizer', () => {
+ const html = '2021
test ';
+ const result = '2021
test
';
+
+ wwe.setValue(html);
+
+ expect(wwe.getValue()).toEqual(result);
+ });
});
diff --git a/libs/toastmark/src/__sample__/index.ts b/libs/toastmark/src/__sample__/index.ts
index 506c368836..86b2ff8e5f 100644
--- a/libs/toastmark/src/__sample__/index.ts
+++ b/libs/toastmark/src/__sample__/index.ts
@@ -57,12 +57,13 @@ cm.on('change', (editor, changeObj) => {
if (startEl) {
startEl.insertAdjacentHTML('beforebegin', newHtml);
let el: Element = startEl;
- while (el !== endEl) {
+ while (el && el !== endEl) {
const nextEl: Element | null = el.nextElementSibling;
el.remove();
el = nextEl!;
}
- el.remove();
+ // eslint-disable-next-line no-unused-expressions
+ el?.remove();
}
}