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

Commit 1646a04

Browse files
committed
merge bold matcher change
2 parents 1efbea8 + 0c2e287 commit 1646a04

File tree

4 files changed

+65
-19
lines changed

4 files changed

+65
-19
lines changed

demo/webpack.config.dev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ var ExtractTextPlugin = require("extract-text-webpack-plugin");
1010
// host so it can load the right files. The HMR host is a bit stranger. For more
1111
// details on why we need this URL see the readme and:
1212
// https://github.com/glenjamin/webpack-hot-middleware/issues/37
13-
var DEV_PORT = process.env.DEV_PORT || 3001;
14-
var DEV_HOST = `//localhost:${DEV_PORT}/`;
13+
var PORT = process.env.PORT || 3001;
14+
var DEV_HOST = `//localhost:${PORT}/`;
1515
var HMR_HOST = `${DEV_HOST}__webpack_hmr`;
1616

1717
module.exports = Object.assign(webpackBaseConfig, {

src/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const CODE_BLOCK_REGEX = /^```([\w-]+)?\s*$/;
22

33
export const inlineMatchers = {
4-
BOLD: [/\*\*([^(?:**)]+)\*\*/g, /__([^(?:__)]+)__/g],
4+
BOLD: [/\*\*([^(?**)]+)\*\*/g, /__([^(?:__)]+)__/g],
55
ITALIC: [/\*([^*]+)\*/g, /_([^_]+)_/g],
66
CODE: [/`([^`]+)`/g],
77
STRIKETHROUGH: [/~~([^(?:~~)]+)~~/g],

src/index.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ import { CODE_BLOCK_REGEX } from "./constants";
2525

2626
const INLINE_STYLE_CHARACTERS = [" ", "*", "_"];
2727

28+
function inCodeBlock(editorState) {
29+
const startKey = editorState.getSelection().getStartKey();
30+
if (startKey) {
31+
const currentBlockType = editorState
32+
.getCurrentContent()
33+
.getBlockForKey(startKey)
34+
.getType();
35+
if (currentBlockType === "code-block") return true;
36+
}
37+
38+
return false;
39+
}
40+
2841
function checkCharacterForState(editorState, character) {
2942
let newEditorState = handleBlockType(editorState, character);
3043
if (editorState === newEditorState) {
@@ -147,14 +160,7 @@ const createMarkdownPlugin = (config = {}) => {
147160
}
148161

149162
// If we're in a code block don't add markdown to it
150-
const startKey = editorState.getSelection().getStartKey();
151-
if (startKey) {
152-
const currentBlockType = editorState
153-
.getCurrentContent()
154-
.getBlockForKey(startKey)
155-
.getType();
156-
if (currentBlockType === "code-block") return "not-handled";
157-
}
163+
if (inCodeBlock(editorState)) return "not-handled";
158164

159165
newEditorState = checkCharacterForState(editorState, "\n");
160166
if (editorState !== newEditorState) {
@@ -168,15 +174,9 @@ const createMarkdownPlugin = (config = {}) => {
168174
if (character !== " ") {
169175
return "not-handled";
170176
}
177+
171178
// If we're in a code block don't add markdown to it
172-
const startKey = editorState.getSelection().getStartKey();
173-
if (startKey) {
174-
const currentBlockType = editorState
175-
.getCurrentContent()
176-
.getBlockForKey(startKey)
177-
.getType();
178-
if (currentBlockType === "code-block") return "not-handled";
179-
}
179+
if (inCodeBlock(editorState)) return "not-handled";
180180

181181
const newEditorState = checkCharacterForState(editorState, character);
182182
if (editorState !== newEditorState) {
@@ -218,6 +218,8 @@ const createMarkdownPlugin = (config = {}) => {
218218
if (html) {
219219
return "not-handled";
220220
}
221+
// If we're in a code block don't add markdown to it
222+
if (inCodeBlock(editorState)) return "not-handled";
221223
let newEditorState = editorState;
222224
let buffer = [];
223225
for (let i = 0; i < text.length; i++) {

src/modifiers/__test__/handleInlineStyle-test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,50 @@ describe.only("handleInlineStyle", () => {
8787
hasFocus: true,
8888
}),
8989
},
90+
"converts semicolons to bold with astarisks": {
91+
before: {
92+
entityMap: {},
93+
blocks: [
94+
{
95+
key: "item1",
96+
text: "hello **TL;DR:** style",
97+
type: "unstyled",
98+
depth: 0,
99+
inlineStyleRanges: [],
100+
entityRanges: [],
101+
data: {},
102+
},
103+
],
104+
},
105+
after: {
106+
entityMap: {},
107+
blocks: [
108+
{
109+
key: "item1",
110+
text: "hello TL;DR: style",
111+
type: "unstyled",
112+
depth: 0,
113+
inlineStyleRanges: [
114+
{
115+
length: 6,
116+
offset: 6,
117+
style: "BOLD",
118+
},
119+
],
120+
entityRanges: [],
121+
data: {},
122+
},
123+
],
124+
},
125+
selection: new SelectionState({
126+
anchorKey: "item1",
127+
anchorOffset: 14,
128+
focusKey: "item1",
129+
focusOffset: 14,
130+
isBackward: false,
131+
hasFocus: true,
132+
}),
133+
},
90134
"converts to bold with underscores": {
91135
before: {
92136
entityMap: {},

0 commit comments

Comments
 (0)