Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit cc8537c

Browse files
committed
Trigger *bold* and _italic_
1 parent b9e11d7 commit cc8537c

File tree

2 files changed

+13
-157
lines changed

2 files changed

+13
-157
lines changed

src/constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { CHECKABLE_LIST_ITEM } from "draft-js-checkable-list-item";
33
export const CODE_BLOCK_REGEX = /^```([\w-]+)?\s*$/;
44

55
export const inlineMatchers = {
6-
BOLD: [/\*\*(.+)\*\*$/g, /__(.+)__$/g],
7-
ITALIC: [/\*(.+)\*$/g, /_(.+)_$/g],
6+
BOLD: [/\*(.+)\*$/g],
7+
ITALIC: [/_(.+)_$/g],
88
CODE: [/`(.+)`$/g],
99
STRIKETHROUGH: [/~~(.+)~~$/g],
1010
};

src/modifiers/__test__/handleInlineStyle-test.js

Lines changed: 11 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe("handleInlineStyle", () => {
5353
blocks: [
5454
{
5555
key: "item1",
56-
text: "`h~~el**lo *inline~~***` style",
56+
text: "`h~~el*lo _inline~~_*` style",
5757
type: "unstyled",
5858
depth: 0,
5959
inlineStyleRanges: [],
@@ -99,9 +99,9 @@ describe("handleInlineStyle", () => {
9999
},
100100
selection: new SelectionState({
101101
anchorKey: "item1",
102-
anchorOffset: 24,
102+
anchorOffset: 22,
103103
focusKey: "item1",
104-
focusOffset: 24,
104+
focusOffset: 22,
105105
isBackward: false,
106106
hasFocus: true,
107107
}),
@@ -113,7 +113,7 @@ describe("handleInlineStyle", () => {
113113
blocks: [
114114
{
115115
key: "item1",
116-
text: "hello **inline** style",
116+
text: "hello *inline* style",
117117
type: "unstyled",
118118
depth: 0,
119119
inlineStyleRanges: [],
@@ -144,9 +144,9 @@ describe("handleInlineStyle", () => {
144144
},
145145
selection: new SelectionState({
146146
anchorKey: "item1",
147-
anchorOffset: 16,
147+
anchorOffset: 14,
148148
focusKey: "item1",
149-
focusOffset: 16,
149+
focusOffset: 14,
150150
isBackward: false,
151151
hasFocus: true,
152152
}),
@@ -195,94 +195,6 @@ describe("handleInlineStyle", () => {
195195
hasFocus: true,
196196
}),
197197
},
198-
"converts to bold with underscores": {
199-
before: {
200-
entityMap: {},
201-
blocks: [
202-
{
203-
key: "item1",
204-
text: "hello __inline__ style",
205-
type: "unstyled",
206-
depth: 0,
207-
inlineStyleRanges: [],
208-
entityRanges: [],
209-
data: {},
210-
},
211-
],
212-
},
213-
after: {
214-
entityMap: {},
215-
blocks: [
216-
{
217-
key: "item1",
218-
text: "hello inline style",
219-
type: "unstyled",
220-
depth: 0,
221-
inlineStyleRanges: [
222-
{
223-
length: 6,
224-
offset: 6,
225-
style: "BOLD",
226-
},
227-
],
228-
entityRanges: [],
229-
data: {},
230-
},
231-
],
232-
},
233-
selection: new SelectionState({
234-
anchorKey: "item1",
235-
anchorOffset: 16,
236-
focusKey: "item1",
237-
focusOffset: 16,
238-
isBackward: false,
239-
hasFocus: true,
240-
}),
241-
},
242-
"converts to italic with astarisk": {
243-
before: {
244-
entityMap: {},
245-
blocks: [
246-
{
247-
key: "item1",
248-
text: "hello *inline* style",
249-
type: "unstyled",
250-
depth: 0,
251-
inlineStyleRanges: [],
252-
entityRanges: [],
253-
data: {},
254-
},
255-
],
256-
},
257-
after: {
258-
entityMap: {},
259-
blocks: [
260-
{
261-
key: "item1",
262-
text: "hello inline style",
263-
type: "unstyled",
264-
depth: 0,
265-
inlineStyleRanges: [
266-
{
267-
length: 6,
268-
offset: 6,
269-
style: "ITALIC",
270-
},
271-
],
272-
entityRanges: [],
273-
data: {},
274-
},
275-
],
276-
},
277-
selection: new SelectionState({
278-
anchorKey: "item1",
279-
anchorOffset: 14,
280-
focusKey: "item1",
281-
focusOffset: 14,
282-
isBackward: false,
283-
hasFocus: true,
284-
}),
285-
},
286198
"converts to italic with underscore": {
287199
before: {
288200
entityMap: {},
@@ -333,7 +245,7 @@ describe("handleInlineStyle", () => {
333245
blocks: [
334246
{
335247
key: "item1",
336-
text: "hello **inline** style",
248+
text: "hello *inline* style",
337249
type: "unstyled",
338250
depth: 0,
339251
inlineStyleRanges: [
@@ -375,9 +287,9 @@ describe("handleInlineStyle", () => {
375287
},
376288
selection: new SelectionState({
377289
anchorKey: "item1",
378-
anchorOffset: 16,
290+
anchorOffset: 14,
379291
focusKey: "item1",
380-
focusOffset: 16,
292+
focusOffset: 14,
381293
isBackward: false,
382294
hasFocus: true,
383295
}),
@@ -473,62 +385,6 @@ describe("handleInlineStyle", () => {
473385

474386
// combine tests
475387

476-
"combines to italic and bold with underscores": {
477-
before: {
478-
entityMap: {},
479-
blocks: [
480-
{
481-
key: "item1",
482-
text: "hello __inline__ style",
483-
type: "unstyled",
484-
depth: 0,
485-
inlineStyleRanges: [
486-
{
487-
length: 4,
488-
offset: 5,
489-
style: "ITALIC",
490-
},
491-
],
492-
entityRanges: [],
493-
data: {},
494-
},
495-
],
496-
},
497-
after: {
498-
entityMap: {},
499-
blocks: [
500-
{
501-
key: "item1",
502-
text: "hello inline style",
503-
type: "unstyled",
504-
depth: 0,
505-
inlineStyleRanges: [
506-
{
507-
length: 2,
508-
offset: 5,
509-
style: "ITALIC",
510-
},
511-
{
512-
length: 6,
513-
offset: 6,
514-
style: "BOLD",
515-
},
516-
],
517-
entityRanges: [],
518-
data: {},
519-
},
520-
],
521-
},
522-
selection: new SelectionState({
523-
anchorKey: "item1",
524-
anchorOffset: 16,
525-
focusKey: "item1",
526-
focusOffset: 16,
527-
isBackward: false,
528-
hasFocus: true,
529-
}),
530-
},
531-
532388
"combines to bold and italic with underscores": {
533389
before: {
534390
entityMap: {},
@@ -610,10 +466,10 @@ describe("handleInlineStyle", () => {
610466
sameEditorState,
611467
character
612468
);
613-
expect(newEditorState).toEqual(sameEditorState);
614469
expect(Draft.convertToRaw(newEditorState.getCurrentContent())).toEqual(
615470
before
616471
);
472+
expect(newEditorState).toEqual(sameEditorState);
617473
});
618474

619475
it("converts markdown to style or block type", () => {
@@ -622,10 +478,10 @@ describe("handleInlineStyle", () => {
622478
editorState,
623479
character
624480
);
625-
expect(newEditorState).not.toEqual(editorState);
626481
expect(Draft.convertToRaw(newEditorState.getCurrentContent())).toEqual(
627482
after
628483
);
484+
expect(newEditorState).not.toEqual(editorState);
629485
});
630486
});
631487
});

0 commit comments

Comments
 (0)