Skip to content

Commit f6341c6

Browse files
committed
Add quote decorator
1 parent 83a46a4 commit f6341c6

File tree

13 files changed

+56
-13
lines changed

13 files changed

+56
-13
lines changed

src/boldDecorator/Bold/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { bold as boldRE } from '../regexp';
2+
import { bold1, bold2 } from '../regexp';
33
import replaceLeafContent from '../../utils/replaceLeafContent';
44

55
export default class Bold extends React.Component {
@@ -12,6 +12,6 @@ export default class Bold extends React.Component {
1212
return React.createElement(component, this.props);
1313
}
1414
const leaf = children[0];
15-
return <strong>{replaceLeafContent(leaf, (text) => text.replace(boldRE, '$2'))}</strong>;
15+
return <strong>{replaceLeafContent(leaf, (text) => text.replace(bold1, '$1').replace(bold2, '$1'))}</strong>;
1616
}
1717
}

src/boldDecorator/boldStrategy.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import findWithRegex from 'find-with-regex';
2-
import { bold as boldRE } from './regexp';
2+
import { bold1, bold2 } from './regexp';
33

44
const findBold = (contentBlock, callback) => {
5-
findWithRegex(boldRE, contentBlock, callback);
5+
findWithRegex(bold1, contentBlock, callback);
6+
findWithRegex(bold2, contentBlock, callback);
67
};
78

89
export default findBold;

src/boldDecorator/regexp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export const bold = /(\*\*|__)([^\1]+)\1/g;
1+
export const bold1 = /\*\*([^(?:**)]+)\*\*/g;
2+
export const bold2 = /__([^(?:__)]+)__/g;

src/emphasisDecorator/Emphasis/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { emphasis as emphasisRE } from '../regexp';
2+
import { emphasis1, emphasis2 } from '../regexp';
33
import replaceLeafContent from '../../utils/replaceLeafContent';
44

55
export default class Emphasis extends React.Component {
@@ -12,6 +12,6 @@ export default class Emphasis extends React.Component {
1212
return React.createElement(component, this.props);
1313
}
1414
const leaf = children[0];
15-
return <em>{replaceLeafContent(leaf, (text) => text.replace(emphasisRE, '$2'))}</em>;
15+
return <em>{replaceLeafContent(leaf, (text) => text.replace(emphasis1, '$1').replace(emphasis2, '$1'))}</em>;
1616
}
1717
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import findWithRegex from 'find-with-regex';
2-
import { emphasis as emphasisRE } from './regexp';
2+
import { emphasis1, emphasis2 } from './regexp';
33

44
const findEmphasis = (contentBlock, callback) => {
5-
findWithRegex(emphasisRE, contentBlock, callback);
5+
findWithRegex(emphasis1, contentBlock, callback);
6+
findWithRegex(emphasis2, contentBlock, callback);
67
};
78

89
export default findEmphasis;

src/emphasisDecorator/regexp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export const emphasis = /(\*|_)([^\1]+)\1/g;
1+
export const emphasis1 = /\*([^*]+)\*/g;
2+
export const emphasis2 = /_([^_]+)_/g;

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import createLinkDecorator from './linkDecorator';
66
import createBoldDecorator from './boldDecorator';
77
import createEmphasisDecorator from './emphasisDecorator';
88
import createStriketroughDecorator from './strikethroughDecorator';
9+
import createQuoteDecorator from './quoteDecorator';
910

1011
const store = {};
1112

@@ -15,6 +16,7 @@ const createMarkdownShortcutsPlugin = (config = {}) => ({
1516
createCheckboxDecorator(config, store),
1617
createLinkDecorator(config, store),
1718
createBoldDecorator(config, store),
19+
createQuoteDecorator(config, store),
1820
createEmphasisDecorator(config, store),
1921
createStriketroughDecorator(config, store),
2022
createHeadingDecorator({ level: 1 }, store),
@@ -35,7 +37,8 @@ const createMarkdownShortcutsPlugin = (config = {}) => ({
3537
return 'not-handled';
3638
},
3739
onChange(editorState) {
38-
console.info(editorState);
40+
// console.info(editorState.toJS());
41+
window.editorState = editorState;
3942
return editorState;
4043
}
4144
});

src/quoteDecorator/Quote/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import { quote as quoteRE } from '../regexp';
3+
import replaceLeafContent from '../../utils/replaceLeafContent';
4+
5+
export default class Quote extends React.Component {
6+
7+
static displayName = 'MarkdownQuote';
8+
9+
render() {
10+
const { component, children } = this.props;
11+
if (component) {
12+
return React.createElement(component, this.props);
13+
}
14+
const leaf = children[0];
15+
return <q>{replaceLeafContent(leaf, (text) => text.replace(quoteRE, '$1'))}</q>;
16+
}
17+
}

src/quoteDecorator/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import decorateComponentWithProps from 'decorate-component-with-props';
2+
import strategy from './quoteStrategy';
3+
import Quote from './Quote';
4+
5+
const createHeadingDecorator = () => {
6+
const component = decorateComponentWithProps(Quote, {});
7+
return { strategy, component };
8+
};
9+
10+
export default createHeadingDecorator;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import findWithRegex from 'find-with-regex';
2+
import { quote as quoteRE } from './regexp';
3+
4+
const findStrikethrough = (contentBlock, callback) => {
5+
findWithRegex(quoteRE, contentBlock, callback);
6+
};
7+
8+
export default findStrikethrough;

0 commit comments

Comments
 (0)