mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
🐛 Fixed line breaks not persisting when used inside email cards
no issue - we allowed line breaks to be created in the text-replacement html input used inside email cards but they were removed as soon as the card's edit mode was left - fixed the clean-text-replacement-html routine so `<br>` atoms aren't stripped - added the soft-return parser to the `<KoenigTextReplacementHtmlInput>` editor options so the `<br>` elements are correctly parsed back into atoms when entering edit mode
This commit is contained in:
parent
17de478a86
commit
9335b57741
2 changed files with 10 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
import * as softReturnParser from '@tryghost/kg-parser-plugins/lib/cards/softReturn';
|
||||
import Component from '@ember/component';
|
||||
import Editor from 'mobiledoc-kit/editor/editor';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
@ -171,7 +172,7 @@ export default class KoenigTextReplacementHtmlInput extends Component {
|
|||
editorOptions.mobiledoc = mobiledoc;
|
||||
editorOptions.showLinkTooltips = false;
|
||||
editorOptions.undoDepth = UNDO_DEPTH;
|
||||
editorOptions.parserPlugins = [];
|
||||
editorOptions.parserPlugins = [softReturnParser.fromBr()];
|
||||
|
||||
editor = new Editor(editorOptions);
|
||||
|
||||
|
|
|
@ -26,7 +26,14 @@ export default function cleanTextReplacementHtml(html = '', _options = {}) {
|
|||
let doc = options.createDocument(cleanHtml);
|
||||
|
||||
doc.body.querySelectorAll('*').forEach((element) => {
|
||||
if (!element.textContent.trim()) {
|
||||
// keep any <br> atoms but clean up surrounding spans
|
||||
if (element.classList.contains('-mobiledoc-kit__atom') && element.querySelector('br')) {
|
||||
const br = document.createElement('br');
|
||||
element.replaceWith(br);
|
||||
element = br;
|
||||
}
|
||||
|
||||
if (!element.textContent.trim() && !element.tagName === 'BR') {
|
||||
if (element.textContent.length > 0) {
|
||||
// keep a single space to avoid collapsing spaces
|
||||
let space = doc.createTextNode(' ');
|
||||
|
|
Loading…
Add table
Reference in a new issue