diff --git a/apps/editor/src/__test__/unit/convertor.spec.ts b/apps/editor/src/__test__/unit/convertor.spec.ts
index 2ed8cdd3ef..6bd84dd137 100644
--- a/apps/editor/src/__test__/unit/convertor.spec.ts
+++ b/apps/editor/src/__test__/unit/convertor.spec.ts
@@ -595,20 +595,7 @@ describe('Convertor', () => {
| ![altText](imgUrl) **mixed**
- [linkText](linkUrl) mixed
|
`;
- const expected = source`
- | thead |
- | ----- |
- | |
- | - ordered
|
- | |
- | |
- | - mixed
|
- | - mixed
|
- | foobaz |
- | ![altText](imgUrl) **mixed**- [linkText](linkUrl) mixed
|
- `;
-
- assertConverting(markdown, `${expected}\n`);
+ assertConverting(markdown, `${markdown}\n`);
});
it('table with unmatched html list', () => {
@@ -1075,30 +1062,6 @@ describe('Convertor', () => {
});
});
- it('should convert by using HTML tag when delimiter is not preceded an alphanumeric', () => {
- const wwNodeJson = {
- type: 'doc',
- content: [
- {
- type: 'paragraph',
- content: [
- {
- type: 'text',
- marks: [{ type: 'strong' }],
- text: '"test"',
- },
- { type: 'text', text: 'a' },
- ],
- },
- ],
- };
- const wwNode = Node.fromJSON(schema, wwNodeJson);
-
- const result = convertor.toMarkdownText(wwNode);
-
- expect(result).toBe(`"test"a`);
- });
-
it('should convert empty line between lists of wysiwig to
', () => {
const wwNodeJson = {
type: 'doc',
diff --git a/apps/editor/src/convertors/toMarkdown/toMdConvertorState.ts b/apps/editor/src/convertors/toMarkdown/toMdConvertorState.ts
index 86fd701a05..9fe47a3567 100644
--- a/apps/editor/src/convertors/toMarkdown/toMdConvertorState.ts
+++ b/apps/editor/src/convertors/toMarkdown/toMdConvertorState.ts
@@ -1,6 +1,6 @@
import { Node, Mark } from 'prosemirror-model';
-import { includes, escape, last, isEndWithSpace, isStartWithSpace } from '@/utils/common';
+import { includes, escape, last } from '@/utils/common';
import { WwNodeType, WwMarkType } from '@t/wysiwyg';
import {
@@ -10,7 +10,6 @@ import {
FirstDelimFn,
InfoForPosSync,
} from '@t/convertor';
-import { DEFAULT_TEXT_NOT_START_OR_END_WITH_SPACE } from '@/utils/constants';
export default class ToMdConvertorState {
private readonly nodeTypeConvertors: ToMdNodeTypeConvertorMap;
@@ -50,27 +49,11 @@ export default class ToMdConvertorState {
return /(^|\n)$/.test(this.result);
}
- private isBetweenSpaces(parent: Node, index: number) {
- const { content } = parent;
-
- const isFrontNodeEndWithSpace =
- index === 0 ||
- isEndWithSpace(content.child(index - 1).text ?? DEFAULT_TEXT_NOT_START_OR_END_WITH_SPACE);
-
- const isRearNodeStartWithSpace =
- index >= content.childCount - 1 ||
- isStartWithSpace(content.child(index + 1).text ?? DEFAULT_TEXT_NOT_START_OR_END_WITH_SPACE);
-
- return isFrontNodeEndWithSpace && isRearNodeStartWithSpace;
- }
-
private markText(mark: Mark, entering: boolean, parent: Node, index: number) {
const convertor = this.getMarkConvertor(mark);
if (convertor) {
- const betweenSpace = this.isBetweenSpaces(parent, entering ? index : index - 1);
-
- const { delim, rawHTML } = convertor({ node: mark, parent, index }, entering, betweenSpace);
+ const { delim, rawHTML } = convertor({ node: mark, parent, index }, entering);
return (rawHTML as string) || (delim as string);
}
diff --git a/apps/editor/src/convertors/toMarkdown/toMdConvertors.ts b/apps/editor/src/convertors/toMarkdown/toMdConvertors.ts
index 8f1a190404..71066e7b18 100644
--- a/apps/editor/src/convertors/toMarkdown/toMdConvertors.ts
+++ b/apps/editor/src/convertors/toMarkdown/toMdConvertors.ts
@@ -208,44 +208,29 @@ export const toMdConvertors: ToMdConvertorMap = {
};
},
- strong({ node }, { entering }, betweenSpace) {
+ strong({ node }, { entering }) {
const { rawHTML } = node.attrs;
- let delim = '**';
-
- if (!betweenSpace) {
- delim = entering ? '' : '';
- }
return {
- delim,
+ delim: '**',
rawHTML: entering ? getOpenRawHTML(rawHTML) : getCloseRawHTML(rawHTML),
};
},
- emph({ node }, { entering }, betweenSpace) {
+ emph({ node }, { entering }) {
const { rawHTML } = node.attrs;
- let delim = '*';
-
- if (!betweenSpace) {
- delim = entering ? '' : '';
- }
return {
- delim,
+ delim: '*',
rawHTML: entering ? getOpenRawHTML(rawHTML) : getCloseRawHTML(rawHTML),
};
},
- strike({ node }, { entering }, betweenSpace) {
+ strike({ node }, { entering }) {
const { rawHTML } = node.attrs;
- let delim = '~~';
-
- if (!betweenSpace) {
- delim = entering ? '' : '';
- }
return {
- delim,
+ delim: '~~',
rawHTML: entering ? getOpenRawHTML(rawHTML) : getCloseRawHTML(rawHTML),
};
},
@@ -368,7 +353,7 @@ function createMarkTypeConvertors(convertors: ToMdConvertorMap) {
const markTypes = Object.keys(markTypeOptions) as WwMarkType[];
markTypes.forEach((type) => {
- markTypeConvertors[type] = (nodeInfo, entering, betweenSpace) => {
+ markTypeConvertors[type] = (nodeInfo, entering) => {
const markOption = markTypeOptions[type];
const convertor = convertors[type];
@@ -377,9 +362,7 @@ function createMarkTypeConvertors(convertors: ToMdConvertorMap) {
// When calling the converter without using `delim` and `rawHTML` values,
// the converter is called without parameters.
const runConvertor = convertor && nodeInfo && !isUndefined(entering);
- const params = runConvertor
- ? convertor!(nodeInfo as MarkInfo, { entering }, betweenSpace)
- : {};
+ const params = runConvertor ? convertor!(nodeInfo as MarkInfo, { entering }) : {};
return { ...params, ...markOption };
};
diff --git a/apps/editor/src/utils/common.ts b/apps/editor/src/utils/common.ts
index 3754219237..642b012c19 100644
--- a/apps/editor/src/utils/common.ts
+++ b/apps/editor/src/utils/common.ts
@@ -263,15 +263,3 @@ export function assign(targetObj: Record, obj: Record
export function getSortedNumPair(valueA: number, valueB: number) {
return valueA > valueB ? [valueB, valueA] : [valueA, valueB];
}
-
-export function isStartWithSpace(text: string) {
- const reStartWithSpace = /^\s(\S*)/g;
-
- return reStartWithSpace.test(text);
-}
-
-export function isEndWithSpace(text: string) {
- const reEndWithSpace = /(\S*)\s$/g;
-
- return reEndWithSpace.test(text);
-}
diff --git a/apps/editor/src/utils/constants.ts b/apps/editor/src/utils/constants.ts
index 78d5adf33f..2d6cd54983 100644
--- a/apps/editor/src/utils/constants.ts
+++ b/apps/editor/src/utils/constants.ts
@@ -20,5 +20,3 @@ export const reBR = /
/i;
export const reHTMLComment = /|/;
export const ALTERNATIVE_TAG_FOR_BR = '';
-
-export const DEFAULT_TEXT_NOT_START_OR_END_WITH_SPACE = 'a';
diff --git a/apps/editor/types/convertor.d.ts b/apps/editor/types/convertor.d.ts
index 718c1c7ade..2ab9c93933 100644
--- a/apps/editor/types/convertor.d.ts
+++ b/apps/editor/types/convertor.d.ts
@@ -113,8 +113,7 @@ export type ToMdNodeTypeConvertorMap = Partial ToMdConvertorReturnValues & ToMdMarkTypeOption;
export type ToMdMarkTypeConvertorMap = Partial>;
@@ -127,8 +126,7 @@ interface ToMdConvertorContext {
type ToMdConvertor = (
nodeInfo: NodeInfo | MarkInfo,
- context: ToMdConvertorContext,
- betweenSpace?: boolean
+ context: ToMdConvertorContext
) => ToMdConvertorReturnValues;
export type ToMdConvertorMap = Partial>;