mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Koenig - HR card with markdown text expansion
refs https://github.com/TryGhost/Ghost/issues/9311 - adds the `koenig-card-hr` card that renders a `<hr>` element - adds text expansion to convert `---` into the new HR card
This commit is contained in:
parent
07d6aee326
commit
3ac59e5ba8
@ -277,14 +277,14 @@
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.__mobiledoc-editor hr {
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cards
|
||||
*/
|
||||
|
||||
.__mobiledoc-card {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tooltips
|
||||
*/
|
||||
|
@ -0,0 +1,7 @@
|
||||
import Component from '@ember/component';
|
||||
import layout from '../templates/components/koenig-card-hr';
|
||||
|
||||
export default Component.extend({
|
||||
tagName: '',
|
||||
layout
|
||||
});
|
@ -1,4 +1,5 @@
|
||||
import createComponentCard from '../utils/create-component-card';
|
||||
|
||||
export default [
|
||||
createComponentCard('koenig-card-hr')
|
||||
];
|
||||
|
@ -64,6 +64,38 @@ export default function (editor) {
|
||||
}
|
||||
});
|
||||
|
||||
editor.onTextInput({
|
||||
name: 'md_hr',
|
||||
match: /^---$/,
|
||||
run(editor) {
|
||||
let {range: {head, head: {section}}} = editor;
|
||||
|
||||
// Skip if cursor is not at end of section
|
||||
if (!head.isTail()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip if section is a list item
|
||||
if (section.isListItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
editor.run((postEditor) => {
|
||||
let card = postEditor.builder.createCardSection('koenig-card-hr');
|
||||
let needsTrailingParagraph = !section.next;
|
||||
|
||||
postEditor.replaceSection(section, card);
|
||||
|
||||
// add an empty paragraph after if necessary so writing can continue
|
||||
if (needsTrailingParagraph) {
|
||||
let newSection = postEditor.builder.createMarkupSection('p');
|
||||
postEditor.insertSectionAtEnd(newSection);
|
||||
postEditor.setRange(newSection.tailPosition());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/* inline markdown ------------------------------------------------------ */
|
||||
|
||||
function matchStrongStar(editor, text) {
|
||||
|
@ -0,0 +1 @@
|
||||
<hr>
|
@ -0,0 +1 @@
|
||||
export {default} from 'koenig-editor/components/koenig-card-hr';
|
Loading…
Reference in New Issue
Block a user