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:
parent
50c3076a35
commit
2093b34c36
6 changed files with 46 additions and 4 deletions
|
@ -277,14 +277,14 @@
|
|||
max-width: 100%;
|
||||
}
|
||||
|
||||
.__mobiledoc-editor hr {
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cards
|
||||
*/
|
||||
|
||||
.__mobiledoc-card {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tooltips
|
||||
*/
|
||||
|
|
7
lib/koenig-editor/addon/components/koenig-card-hr.js
Normal file
7
lib/koenig-editor/addon/components/koenig-card-hr.js
Normal file
|
@ -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>
|
1
lib/koenig-editor/app/components/koenig-card-hr.js
Normal file
1
lib/koenig-editor/app/components/koenig-card-hr.js
Normal file
|
@ -0,0 +1 @@
|
|||
export {default} from 'koenig-editor/components/koenig-card-hr';
|
Loading…
Reference in a new issue