1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01: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:
Kevin Ansfield 2018-01-30 15:19:30 +00:00
parent 50c3076a35
commit 2093b34c36
6 changed files with 46 additions and 4 deletions

View file

@ -277,14 +277,14 @@
max-width: 100%;
}
.__mobiledoc-editor hr {
margin: 0.5em 0;
}
/**
* Cards
*/
.__mobiledoc-card {
display: inline-block;
}
/**
* Tooltips
*/

View file

@ -0,0 +1,7 @@
import Component from '@ember/component';
import layout from '../templates/components/koenig-card-hr';
export default Component.extend({
tagName: '',
layout
});

View file

@ -1,4 +1,5 @@
import createComponentCard from '../utils/create-component-card';
export default [
createComponentCard('koenig-card-hr')
];

View file

@ -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) {

View file

@ -0,0 +1 @@
<hr>

View file

@ -0,0 +1 @@
export {default} from 'koenig-editor/components/koenig-card-hr';