mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03: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
@ -343,7 +343,24 @@ export default Component.extend({
|
||||
// - first section must be a markerable section
|
||||
// - if first section is a list, grab the content of the first list item
|
||||
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
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user