mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Prevent {} text replacements from receiving any formatting
no issue - we don't want to allow text replacement strings to be split in half by html tags so we disallow any formats to be applied to them - in the `<KoenigTextReplacementHtmlInput>`'s mobiledoc editor's `didUpdatePost` hook handler we loop over all markers in the post and if they have a code markup (we use this to represent replacement strings) then we strip any other markups
This commit is contained in:
parent
01faf606a6
commit
abcb9da445
1 changed files with 18 additions and 19 deletions
|
@ -343,7 +343,24 @@ export default Component.extend({
|
||||||
// - first section must be a markerable section
|
// - first section must be a markerable section
|
||||||
// - if first section is a list, grab the content of the first list item
|
// - if first section is a list, grab the content of the first list item
|
||||||
didUpdatePost(postEditor) {
|
didUpdatePost(postEditor) {
|
||||||
let {builder, editor, editor: {post}} = postEditor;
|
let {editor, editor: {post, range}} = postEditor;
|
||||||
|
|
||||||
|
// remove any other formatting from code formats
|
||||||
|
let markers = [];
|
||||||
|
try {
|
||||||
|
markers = post.markersContainedByRange(post.toRange());
|
||||||
|
} catch (e) {
|
||||||
|
// post.toRange() can fail if a list item was just removed
|
||||||
|
// TODO: mobiledoc-kit bug?
|
||||||
|
}
|
||||||
|
markers.forEach((marker) => {
|
||||||
|
let {markups} = marker;
|
||||||
|
if (markups.length > 1 && marker.hasMarkup('code')) {
|
||||||
|
markups.rejectBy('tagName', 'code').forEach((markup) => {
|
||||||
|
marker.removeMarkup(markup);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// remove any non-markerable/non-list sections
|
// remove any non-markerable/non-list sections
|
||||||
post.sections.forEach((section) => {
|
post.sections.forEach((section) => {
|
||||||
|
@ -355,24 +372,6 @@ export default Component.extend({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// strip all sections other than the first
|
|
||||||
// if (post.sections.length > 1) {
|
|
||||||
// while (post.sections.length > 1) {
|
|
||||||
// postEditor.removeSection(post.sections.tail);
|
|
||||||
// }
|
|
||||||
// postEditor.setRange(post.sections.head.tailPosition());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// convert list section to a paragraph section
|
|
||||||
if (post.sections.head.isListSection) {
|
|
||||||
let list = post.sections.head;
|
|
||||||
let listItem = list.items.head;
|
|
||||||
let newMarkers = listItem.markers.map(m => m.clone());
|
|
||||||
let p = builder.createMarkupSection('p', newMarkers);
|
|
||||||
postEditor.replaceSection(list, p);
|
|
||||||
postEditor.setRange(post.sections.head.tailPosition());
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
postDidChange() {
|
postDidChange() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue