Skip to content

Add DOM Parsing and Serialization types #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3480,7 +3480,7 @@ declare var DOMMatrixReadOnly: {
};

interface DOMParser {
parseFromString(source: string, mimeType: string): Document;
parseFromString(str: string, type: SupportedType): Document;
}

declare var DOMParser: {
Expand Down Expand Up @@ -4648,6 +4648,7 @@ interface Element extends Node, ParentNode, NonDocumentTypeChildNode, ChildNode,
* change it.
*/
id: string;
innerHTML: string;
/**
* Returns the local name.
*/
Expand All @@ -4656,6 +4657,7 @@ interface Element extends Node, ParentNode, NonDocumentTypeChildNode, ChildNode,
* Returns the namespace.
*/
readonly namespaceURI: string | null;
outerHTML: string;
/**
* Returns the namespace prefix.
*/
Expand Down Expand Up @@ -4775,6 +4777,10 @@ declare var Element: {
new(): Element;
};

interface ElementCSSInlineStyle {
readonly style: CSSStyleDeclaration;
}

interface ElementContentEditable {
contentEditable: string;
inputMode: string;
Expand Down Expand Up @@ -6016,7 +6022,7 @@ declare var HTMLDocument: {
interface HTMLElementEventMap extends GlobalEventHandlersEventMap, DocumentAndElementEventHandlersEventMap {
}

interface HTMLElement extends Element, GlobalEventHandlers, DocumentAndElementEventHandlers, ElementContentEditable, HTMLOrSVGElement {
interface HTMLElement extends Element, GlobalEventHandlers, DocumentAndElementEventHandlers, ElementContentEditable, HTMLOrSVGElement, ElementCSSInlineStyle {
accessKey: string;
readonly accessKeyLabel: string;
autocapitalize: string;
Expand Down Expand Up @@ -11707,6 +11713,7 @@ interface Range extends AbstractRange {
* in the range, and 1 if the point is after the range.
*/
comparePoint(node: Node, offset: number): number;
createContextualFragment(fragment: string): DocumentFragment;
deleteContents(): void;
detach(): void;
extractContents(): DocumentFragment;
Expand Down Expand Up @@ -12116,7 +12123,7 @@ declare var SVGDescElement: {
interface SVGElementEventMap extends GlobalEventHandlersEventMap, DocumentAndElementEventHandlersEventMap {
}

interface SVGElement extends Element, GlobalEventHandlers, DocumentAndElementEventHandlers, SVGElementInstance, HTMLOrSVGElement {
interface SVGElement extends Element, GlobalEventHandlers, DocumentAndElementEventHandlers, SVGElementInstance, HTMLOrSVGElement, ElementCSSInlineStyle {
/** @deprecated */
readonly className: any;
readonly ownerSVGElement: SVGSVGElement | null;
Expand Down Expand Up @@ -16708,7 +16715,7 @@ declare var XMLHttpRequestUpload: {
};

interface XMLSerializer {
serializeToString(target: Node): string;
serializeToString(root: Node): string;
}

declare var XMLSerializer: {
Expand Down Expand Up @@ -17705,6 +17712,7 @@ type ServiceWorkerUpdateViaCache = "imports" | "all" | "none";
type ShadowRootMode = "open" | "closed";
type SpeechRecognitionErrorCode = "no-speech" | "aborted" | "audio-capture" | "network" | "not-allowed" | "service-not-allowed" | "bad-grammar" | "language-not-supported";
type SpeechSynthesisErrorCode = "canceled" | "interrupted" | "audio-busy" | "audio-hardware" | "network" | "synthesis-unavailable" | "synthesis-failed" | "language-unavailable" | "voice-unavailable" | "text-too-long" | "invalid-argument";
type SupportedType = "text/html" | "text/xml" | "application/xml" | "application/xhtml+xml" | "image/svg+xml";
type TextTrackKind = "subtitles" | "captions" | "descriptions" | "chapters" | "metadata";
type TextTrackMode = "disabled" | "hidden" | "showing";
type TouchType = "direct" | "stylus";
Expand Down
4 changes: 3 additions & 1 deletion inputfiles/addedTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@
},
"SVGElement": {
"implements": [
"ElementCSSInlineStyle",
"GlobalEventHandlers",
"DocumentAndElementEventHandlers"
]
Expand Down Expand Up @@ -2097,7 +2098,8 @@
{
"name": "wbr"
}
]
],
"implements": ["ElementCSSInlineStyle"]
},
"HTMLFormElement": {
"element": [
Expand Down
27 changes: 27 additions & 0 deletions inputfiles/idl/DOM Parsing and Serialization.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Constructor, Exposed=Window]
interface DOMParser {
[NewObject] Document parseFromString(DOMString str, SupportedType type);
};

enum SupportedType {
"text/html",
"text/xml",
"application/xml",
"application/xhtml+xml",
"image/svg+xml"
};

[Constructor, Exposed=Window]
interface XMLSerializer {
DOMString serializeToString(Node root);
};

partial interface Element {
[CEReactions, TreatNullAs=EmptyString] attribute DOMString innerHTML;
[CEReactions, TreatNullAs=EmptyString] attribute DOMString outerHTML;
[CEReactions] void insertAdjacentHTML(DOMString position, DOMString text);
};

partial interface Range {
[CEReactions, NewObject] DocumentFragment createContextualFragment(DOMString fragment);
};
4 changes: 4 additions & 0 deletions inputfiles/idlSources.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"url": "https://dom.spec.whatwg.org/",
"title": "DOM"
},
{
"url": "https://w3c.github.io/DOM-Parsing/",
"title": "DOM Parsing and Serialization"
},
{
"url": "https://encoding.spec.whatwg.org/",
"title": "Encoding"
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"jsdom": "^11.11.0",
"node-fetch": "^2.1.1",
"print-diff": "^0.1.1",
"typescript": "next",
"typescript": "^2.9.2",
"webidl2": "^13.0.2"
}
}
5 changes: 4 additions & 1 deletion src/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function fetchIDL(source: IDLSource) {
}

function processComments(dom: DocumentFragment) {
const elements = Array.from(dom.querySelectorAll("dl.domintro"));
const elements = dom.querySelectorAll("dl.domintro");
if (!elements.length) {
return undefined;
}
Expand All @@ -72,6 +72,9 @@ function processComments(dom: DocumentFragment) {
}
}
}
if (!Object.keys(result).length) {
return undefined;
}
return JSON.stringify(result, undefined, 4);
}

Expand Down