From 002801a2608646e0405193d2f5e7faa6cb23b23c Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 21 May 2024 13:22:00 +0400 Subject: [PATCH] Add `doctype` property --- src/common/index.ts | 2 +- src/dom_components/model/ComponentWrapper.ts | 6 +++++- src/parser/config/config.ts | 9 ++------- test/specs/dom_components/index.ts | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/common/index.ts b/src/common/index.ts index 8b82cbcbf..bd983b2c3 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -27,7 +27,7 @@ export type Nullable = undefined | null | false; export interface OptionAsDocument { /** - * Treat the HTML string as document (option valid on the root component, eg. will include ``, ``, etc.). + * Treat the HTML string as document (option valid on the root component, eg. will include doctype, html, head, etc.). */ asDocument?: boolean; } diff --git a/src/dom_components/model/ComponentWrapper.ts b/src/dom_components/model/ComponentWrapper.ts index a1d44789c..d8988823b 100644 --- a/src/dom_components/model/ComponentWrapper.ts +++ b/src/dom_components/model/ComponentWrapper.ts @@ -55,8 +55,12 @@ export default class ComponentWrapper extends Component { return this.get('docEl'); } + get doctype(): string { + return this.attributes.doctype || ''; + } + toHTML(opts: ToHTMLOptions = {}) { - const { doctype = '' } = this.attributes; + const { doctype } = this; const asDoc = !isUndefined(opts.asDocument) ? opts.asDocument : !!doctype; const { head, docEl } = this; const body = super.toHTML(opts); diff --git a/src/parser/config/config.ts b/src/parser/config/config.ts index 060747fa5..058045c70 100644 --- a/src/parser/config/config.ts +++ b/src/parser/config/config.ts @@ -1,3 +1,4 @@ +import { OptionAsDocument } from '../../common'; import { CssRuleJSON } from '../../css_composer/model/CssRule'; import { ComponentDefinitionDefined } from '../../dom_components/model/types'; import Editor from '../../editor'; @@ -26,7 +27,7 @@ export interface ParseNodeOptions extends HTMLParserOptions { skipChildren?: boolean; } -export interface HTMLParserOptions { +export interface HTMLParserOptions extends OptionAsDocument { /** * DOMParser mime type. * If you use the `text/html` parser, it will fix the invalid syntax automatically. @@ -35,12 +36,6 @@ export interface HTMLParserOptions { */ htmlType?: DOMParserSupportedType; - /** - * Parse the string as HTML document. The result will include additional data (eg. doctype, head, etc.) - * @default false - */ - asDocument?: boolean; - /** * Allow