mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
32 lines
1002 B
JavaScript
32 lines
1002 B
JavaScript
import Component from '@glimmer/component';
|
|
import cleanBasicHtml from '@tryghost/kg-clean-basic-html';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default class AnnouncementSettingsContentComponent extends Component {
|
|
@service feature;
|
|
@service settings;
|
|
|
|
get content() {
|
|
const content = this.settings.announcementContent;
|
|
if (!content) {
|
|
return null;
|
|
}
|
|
// wrap in a paragraph, so it gets parsed correctly
|
|
return this.hasParagraphWrapper(content) ? content : `<p>${content}</p>`;
|
|
}
|
|
|
|
hasParagraphWrapper(html) {
|
|
const domParser = new DOMParser();
|
|
const doc = domParser.parseFromString(html, 'text/html');
|
|
|
|
return doc.body?.firstElementChild?.tagName === 'P';
|
|
}
|
|
|
|
@action
|
|
setContent(html) {
|
|
const cleanedHtml = cleanBasicHtml(html || '', {firstChildInnerContent: true});
|
|
this.settings.announcementContent = cleanedHtml;
|
|
}
|
|
}
|