Skip to content

Commit

Permalink
✨ Koenig - Allow > expansion to convert existing text to blockquotes
Browse files Browse the repository at this point in the history
refs TryGhost/Ghost#9623
- match `> ` behaviour to `# ` behaviour so entering it at the beginning of an existing paragraph will convert that paragraph to a blockquote
  • Loading branch information
kevinansfield committed May 23, 2018
1 parent 1ffed70 commit 0f8ef2b
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/koenig-editor/addon/options/text-expansions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
replaceWithHeaderSection,
replaceWithListSection
} from 'mobiledoc-kit/editor/text-input-handlers';
import {run} from '@ember/runloop';
Expand All @@ -19,7 +18,7 @@ export default function (editor, koenig) {
let hashes = matches[1];
let headingTag = `h${hashes.length}`;
let {range} = editor;
let text = editor.range.head.section.textUntil(editor.range.head);
let text = range.head.section.textUntil(range.head);

// we don't want to convert to a heading if the user has not just
// finished typing the markdown (eg, they've made a previous
Expand All @@ -34,6 +33,7 @@ export default function (editor, koenig) {
let position = postEditor.deleteRange(range);
postEditor.setRange(position);

// toggleHeaderSection will remove all formatting except links
koenig.send('toggleHeaderSection', headingTag, postEditor);
});
}
Expand All @@ -50,9 +50,24 @@ export default function (editor, koenig) {

editor.onTextInput({
name: 'md_blockquote',
match: /^> $/,
run(editor) {
replaceWithHeaderSection(editor, 'blockquote');
match: /^> /,
run(editor, matches) {
let {range} = editor;
let {head, head: {section}} = range;
let text = section.textUntil(head);

// ensure cursor is at the end of the matched text so we don't
// convert text the users wants to start with `> ` and that we're
// not already on a blockquote section
if (text === matches[0] && section.tagName !== 'blockquote') {
editor.run((postEditor) => {
range = range.extend(-(matches[0].length));
let position = postEditor.deleteRange(range);
postEditor.setRange(position);

koenig.send('toggleSection', 'blockquote', postEditor);
});
}
}
});

Expand Down

0 comments on commit 0f8ef2b

Please sign in to comment.