Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 0 additions & 109 deletions src/__test__/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,115 +660,6 @@ describe("draft-js-markdown-plugin", () => {
expect(store.setEditorState).toHaveBeenCalledWith(newEditorState);
});
});
describe("handlePastedText", () => {
let pastedText;
let html;
beforeEach(() => {
pastedText = `_hello world_
Hello`;
html = undefined;
subject = () =>
plugin.handlePastedText(
pastedText,
html,
store.getEditorState(),
store
);
});
[
"replaceText",
// TODO(@mxstbr): This broke when switching mocha->jest, fix it!
// 'insertEmptyBlock',
"handleBlockType",
"handleImage",
"handleLink",
"handleInlineStyle",
].forEach(modifier => {
describe(modifier, () => {
beforeEach(() => {
createMarkdownPlugin.__Rewire__(modifier, modifierSpy); // eslint-disable-line no-underscore-dangle
});
it("returns handled", () => {
expect(subject()).toBe("handled");
expect(modifierSpy).toHaveBeenCalled();
});
});
});
describe("nothing in clipboard", () => {
beforeEach(() => {
pastedText = "";
});
it("returns not-handled", () => {
expect(subject()).toBe("not-handled");
});
});
describe("pasted just text", () => {
beforeEach(() => {
pastedText = "hello";
createMarkdownPlugin.__Rewire__("replaceText", modifierSpy); // eslint-disable-line no-underscore-dangle
});
it("returns handled", () => {
expect(subject()).toBe("handled");
expect(modifierSpy).toHaveBeenCalledWith(
currentEditorState,
"hello"
);
});
});
describe("pasted just text with new line code", () => {
beforeEach(() => {
pastedText = "hello\nworld";
const rawContentState = {
entityMap: {},
blocks: [
{
key: "item1",
text: "",
type: "unstyled",
depth: 0,
inlineStyleRanges: [],
entityRanges: [],
data: {},
},
],
};
const otherRawContentState = {
entityMap: {},
blocks: [
{
key: "item2",
text: "H1",
type: "header-one",
depth: 0,
inlineStyleRanges: [],
entityRanges: [],
data: {},
},
],
};
/* eslint-disable no-underscore-dangle */
createMarkdownPlugin.__Rewire__("replaceText", () =>
createEditorState(rawContentState, currentSelectionState)
);
createMarkdownPlugin.__Rewire__("checkReturnForState", () =>
createEditorState(otherRawContentState, currentSelectionState)
);
/* eslint-enable no-underscore-dangle */
});
it("return handled", () => {
expect(subject()).toBe("handled");
});
});
describe("passed `html` argument", () => {
beforeEach(() => {
pastedText = "# hello";
html = "<h1>hello</h1>";
});
it("returns not-handled", () => {
expect(subject()).toBe("not-handled");
});
});
});
});
});
});
58 changes: 0 additions & 58 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,64 +415,6 @@ const createMarkdownPlugin = (_config = {}) => {
}
}
},
handlePastedText(text, html, editorState, { setEditorState }) {
let newEditorState = editorState;
let buffer = [];

if (html) {
return "not-handled";
}

// If we're in a code block don't add markdown to it
if (inCodeBlock(editorState)) {
setEditorState(insertText(editorState, text));
return "handled";
}

for (let i = 0; i < text.length; i++) {
// eslint-disable-line no-plusplus
if (INLINE_STYLE_CHARACTERS.indexOf(text[i]) >= 0) {
newEditorState = replaceText(
newEditorState,
buffer.join("") + text[i]
);
newEditorState = checkCharacterForState(
config,
newEditorState,
text[i]
);
buffer = [];
} else if (text[i].charCodeAt(0) === 10) {
newEditorState = replaceText(newEditorState, buffer.join(""));
const tmpEditorState = checkReturnForState(
config,
newEditorState,
{}
);
if (newEditorState === tmpEditorState) {
newEditorState = insertEmptyBlock(tmpEditorState);
} else {
newEditorState = tmpEditorState;
}
buffer = [];
} else if (i === text.length - 1) {
newEditorState = replaceText(
newEditorState,
buffer.join("") + text[i]
);
buffer = [];
} else {
buffer.push(text[i]);
}
}

if (editorState !== newEditorState) {
setEditorState(newEditorState);
return "handled";
}

return "not-handled";
},
};
};

Expand Down