diff --git a/src/common/index.ts b/src/common/index.ts index 6f9f74c93..943d4ad02 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -1,4 +1,5 @@ import Backbone from 'backbone'; +import { HTMLParserOptions } from '../parser/config/config'; export { default as $ } from '../utils/cash-dom'; interface NOOP {} @@ -13,6 +14,8 @@ export type DisableOptions = { fromMove?: boolean }; export type LocaleOptions = { locale?: boolean }; +export type WithHTMLParserOptions = { parserOptions?: HTMLParserOptions }; + export type RemoveOptions = Backbone.Silenceable; export type EventHandler = Backbone.EventHandler; diff --git a/src/dom_components/model/Components.ts b/src/dom_components/model/Components.ts index 878ae0b07..452fd30ee 100644 --- a/src/dom_components/model/Components.ts +++ b/src/dom_components/model/Components.ts @@ -1,6 +1,6 @@ import { isEmpty, isArray, isString, isFunction, each, includes, extend, flatten, keys } from 'underscore'; import Component from './Component'; -import { AddOptions, Collection, OptionAsDocument } from '../../common'; +import { AddOptions, Collection } from '../../common'; import { DomComponentsConfig } from '../config/config'; import EditorModel from '../../editor/model/Editor'; import ComponentManager from '..'; @@ -15,7 +15,7 @@ import { } from './types'; import ComponentText from './ComponentText'; import ComponentWrapper from './ComponentWrapper'; -import { ComponentsEvents } from '../types'; +import { ComponentsEvents, ParseStringOptions } from '../types'; import { isSymbolInstance, isSymbolRoot, updateSymbolComps } from './SymbolUtils'; export const getComponentIds = (cmp?: Component | Component[] | Components, res: string[] = []) => { @@ -252,11 +252,11 @@ Component> { return new model(attrs, options) as Component; } - parseString(value: string, opt: AddOptions & OptionAsDocument & { temporary?: boolean; keepIds?: string[] } = {}) { + parseString(value: string, opt: ParseStringOptions = {}) { const { em, domc, parent } = this; const asDocument = opt.asDocument && parent?.is('wrapper'); const cssc = em.Css; - const parsed = em.Parser.parseHtml(value, { asDocument }); + const parsed = em.Parser.parseHtml(value, { asDocument, ...opt.parserOptions }); let components = parsed.html; if (asDocument) { diff --git a/src/dom_components/types.ts b/src/dom_components/types.ts index fbca11658..e62ce1514 100644 --- a/src/dom_components/types.ts +++ b/src/dom_components/types.ts @@ -1,3 +1,4 @@ +import { AddOptions, OptionAsDocument, WithHTMLParserOptions } from '../common'; import Component from './model/Component'; export enum ActionLabelComponents { @@ -16,6 +17,10 @@ export interface SymbolInfo { relatives: Component[]; } +export interface ParseStringOptions extends AddOptions, OptionAsDocument, WithHTMLParserOptions { + keepIds?: string[]; +} + export enum ComponentsEvents { /** * @event `component:add` New component added. diff --git a/src/dom_components/view/ComponentTextView.ts b/src/dom_components/view/ComponentTextView.ts index d67ec3521..8fcd42493 100644 --- a/src/dom_components/view/ComponentTextView.ts +++ b/src/dom_components/view/ComponentTextView.ts @@ -1,5 +1,5 @@ import { bindAll } from 'underscore'; -import { AddOptions, DisableOptions, ObjectAny } from '../../common'; +import { AddOptions, DisableOptions, ObjectAny, WithHTMLParserOptions } from '../../common'; import RichTextEditorModule from '../../rich_text_editor'; import RichTextEditor from '../../rich_text_editor/model/RichTextEditor'; import { off, on } from '../../utils/dom'; @@ -108,7 +108,7 @@ export default class ComponentTextView