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

Commit 380c8c2

Browse files
authored
Merge pull request #26 from withspectrum/inline-styling-in-code-blocks
Disable all inline styling in code blocks
2 parents f9526de + 0b99407 commit 380c8c2

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
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/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++) {

0 commit comments

Comments
 (0)