mirror of
https://github.com/TryGhost/Ghost-Admin.git
synced 2023-12-14 02:33:04 +01:00
Use extracted @tryghost/kg-clean-basic-html package
no issue - `cleanBasicHtml` has been extracted to an external package so that it can be used inside the extracted `@tryghost/kg-parser-plugins` package server-side
This commit is contained in:
parent
2c69970ff2
commit
3bcb56225d
|
@ -1,5 +1,6 @@
|
|||
import Component from '@ember/component';
|
||||
import Editor from 'mobiledoc-kit/editor/editor';
|
||||
import cleanBasicHtml from '@tryghost/kg-clean-basic-html';
|
||||
import layout from '../templates/components/koenig-basic-html-input';
|
||||
import parserPlugins from '../options/basic-html-parser-plugins';
|
||||
import registerKeyCommands, {BASIC_KEY_COMMANDS} from '../options/key-commands';
|
||||
|
@ -8,7 +9,6 @@ import {DRAG_DISABLED_DATA_ATTR} from '../lib/dnd/constants';
|
|||
import {MOBILEDOC_VERSION} from 'mobiledoc-kit/renderers/mobiledoc';
|
||||
import {arrayToMap, toggleSpecialFormatEditState} from './koenig-editor';
|
||||
import {assign} from '@ember/polyfills';
|
||||
import {cleanBasicHtml} from '../helpers/clean-basic-html';
|
||||
import {computed} from '@ember/object';
|
||||
import {getContentFromPasteEvent} from 'mobiledoc-kit/utils/parse-utils';
|
||||
import {getLinkMarkupFromRange} from '../utils/markup-utils';
|
||||
|
|
|
@ -1,38 +1,13 @@
|
|||
import cleanBasicHtml from '@tryghost/kg-clean-basic-html';
|
||||
import {helper} from '@ember/component/helper';
|
||||
import {isArray} from '@ember/array';
|
||||
|
||||
export function cleanBasicHtml(html = '') {
|
||||
export function cleanBasicHtmlHelper(html = '') {
|
||||
if (isArray(html)) {
|
||||
html = html[0] || '';
|
||||
}
|
||||
|
||||
let cleanHtml = html
|
||||
.replace(/<br>/g, ' ')
|
||||
.replace(/(\s| ){2,}/g, ' ')
|
||||
.trim()
|
||||
.replace(/^ | $/g, '')
|
||||
.trim();
|
||||
|
||||
// remove any elements that have a blank textContent
|
||||
if (cleanHtml) {
|
||||
let doc = new DOMParser().parseFromString(cleanHtml, 'text/html');
|
||||
|
||||
doc.body.querySelectorAll('*').forEach((element) => {
|
||||
if (!element.textContent.trim()) {
|
||||
if (element.textContent.length > 0) {
|
||||
// keep a single space to avoid collapsing spaces
|
||||
let space = document.createTextNode(' ');
|
||||
element.replaceWith(space);
|
||||
} else {
|
||||
element.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cleanHtml = doc.body.innerHTML;
|
||||
}
|
||||
|
||||
return cleanHtml;
|
||||
return cleanBasicHtml(html);
|
||||
}
|
||||
|
||||
export default helper(cleanBasicHtml);
|
||||
export default helper(cleanBasicHtmlHelper);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {cleanBasicHtml} from 'koenig-editor/helpers/clean-basic-html';
|
||||
import cleanBasicHtml from '@tryghost/kg-clean-basic-html';
|
||||
|
||||
// mobiledoc by default ignores <BR> tags but we have a custom SoftReturn atom
|
||||
export function brToSoftBreakAtom(node, builder, {addMarkerable, nodeFinished}) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
export {default, cleanBasicHtml} from 'koenig-editor/helpers/clean-basic-html';
|
||||
export {default} from 'koenig-editor/helpers/clean-basic-html';
|
||||
|
|
|
@ -11,9 +11,10 @@
|
|||
"ember-addon"
|
||||
],
|
||||
"dependencies": {
|
||||
"ember-cli-babel": "^7.5.0",
|
||||
"ember-cli-htmlbars": "^3.0.1",
|
||||
"@tryghost/helpers": "^1.1.1",
|
||||
"ember-auto-import": "^1.2.21"
|
||||
"@tryghost/kg-clean-basic-html": "*",
|
||||
"ember-auto-import": "^1.2.21",
|
||||
"ember-cli-babel": "^7.5.0",
|
||||
"ember-cli-htmlbars": "^3.0.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
"@ember/optional-features": "0.7.0",
|
||||
"@html-next/vertical-collection": "1.0.0-beta.13",
|
||||
"@tryghost/helpers": "1.1.2",
|
||||
"@tryghost/kg-clean-basic-html": "0.1.0",
|
||||
"@tryghost/mobiledoc-kit": "0.11.2-ghost.1",
|
||||
"@tryghost/timezone-data": "0.2.1",
|
||||
"autoprefixer": "9.5.1",
|
||||
|
|
|
@ -825,6 +825,11 @@
|
|||
dependencies:
|
||||
lodash-es "^4.17.11"
|
||||
|
||||
"@tryghost/kg-clean-basic-html@0.1.0":
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@tryghost/kg-clean-basic-html/-/kg-clean-basic-html-0.1.0.tgz#49fe824104236858f74c3113e6fc96dc3898a300"
|
||||
integrity sha512-S/BsV6mFXoC8BsLL3WjfZYy2MMiWVrJA5mieNwkYluytSuP8sWUhf5WdNbuXeu5FfnKL9xRttBCc34svp9VIlw==
|
||||
|
||||
"@tryghost/mobiledoc-kit@0.11.2-ghost.1":
|
||||
version "0.11.2-ghost.1"
|
||||
resolved "https://registry.yarnpkg.com/@tryghost/mobiledoc-kit/-/mobiledoc-kit-0.11.2-ghost.1.tgz#7088eb9eef06b4ccdd6c221613f20d01b106f939"
|
||||
|
|
Loading…
Reference in a new issue