Skip to content

Commit 035b9fa

Browse files
committed
feat: implement horizontal line functionality to markdown editor
1 parent beeec2a commit 035b9fa

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

packages/decap-cms-locales/src/en/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const en = {
166166
quote: 'Quote',
167167
bulletedList: 'Bulleted List',
168168
numberedList: 'Numbered List',
169+
horizontalLine: 'Horizontal Line',
169170
addComponent: 'Add Component',
170171
richText: 'Rich Text',
171172
markdown: 'Markdown',

packages/decap-cms-ui-default/src/Icon/images/_index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import iconH1 from './h1.svg';
2222
import iconH2 from './h2.svg';
2323
import iconHOptions from './h-options.svg';
2424
import iconHome from './home.svg';
25+
import iconHorizontalLine from './horizontal-line.svg';
2526
import iconImage from './image.svg';
2627
import iconInfoCircle from './info-circle.svg';
2728
import iconItalic from './italic.svg';
@@ -75,6 +76,7 @@ const images = {
7576
h2: iconH2,
7677
hOptions: iconHOptions,
7778
home: iconHome,
79+
'horizontal-line': iconHorizontalLine,
7880
image: iconImage,
7981
'info-circle': iconInfoCircle,
8082
italic: iconItalic,
Lines changed: 3 additions & 0 deletions
Loading

packages/decap-cms-widget-markdown/src/MarkdownControl/Toolbar.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default class Toolbar extends React.Component {
7474
onMarkClick: PropTypes.func,
7575
onBlockClick: PropTypes.func,
7676
onLinkClick: PropTypes.func,
77+
onInsertHorizontalLine: PropTypes.func,
7778
hasMark: PropTypes.func,
7879
hasInline: PropTypes.func,
7980
hasBlock: PropTypes.func,
@@ -97,6 +98,13 @@ export default class Toolbar extends React.Component {
9798
this.props.onBlockClick(type);
9899
};
99100

101+
handleHorizontalLineClick = event => {
102+
if (event) {
103+
event.preventDefault();
104+
}
105+
this.props.onInsertHorizontalLine();
106+
};
107+
100108
handleMarkClick = (event, type) => {
101109
event.preventDefault();
102110
this.props.onMarkClick(type);
@@ -263,6 +271,16 @@ export default class Toolbar extends React.Component {
263271
disabled={disabled}
264272
/>
265273
)}
274+
{isVisible('horizontal-line') && (
275+
<ToolbarButton
276+
type="thematic-break"
277+
label={t('editor.editorWidgets.markdown.horizontalLine')}
278+
icon="horizontal-line"
279+
onClick={this.handleHorizontalLineClick}
280+
isActive={false}
281+
disabled={disabled}
282+
/>
283+
)}
266284
{showEditorComponents && (
267285
<ToolbarDropdownWrapper>
268286
<Dropdown

packages/decap-cms-widget-markdown/src/MarkdownControl/VisualEditor.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ function Editor(props) {
167167
insertShortcode(editor, pluginConfig);
168168
}
169169

170+
function handleInsertHorizontalLine() {
171+
Transforms.insertNodes(editor, {
172+
type: 'thematic-break',
173+
children: [{ text: '' }],
174+
});
175+
ReactEditor.focus(editor);
176+
}
177+
170178
function handleKeyDown(event) {
171179
for (const handler of editor.keyDownHandlers || []) {
172180
if (handler(event, editor) === false) {
@@ -231,6 +239,7 @@ function Editor(props) {
231239
onMarkClick={handleMarkClick}
232240
onBlockClick={handleBlockClick}
233241
onLinkClick={handleLinkClick}
242+
onInsertHorizontalLine={handleInsertHorizontalLine}
234243
onToggleMode={handleToggleMode}
235244
plugins={editorComponents}
236245
onSubmit={handleInsertShortcode}

packages/decap-cms-widget-markdown/src/schema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default {
2121
'quote',
2222
'bulleted-list',
2323
'numbered-list',
24+
'horizontal-line',
2425
],
2526
},
2627
},

0 commit comments

Comments
 (0)