WebReflection / linkedom

A triple-linked lists based DOM implementation.
https://webreflection.medium.com/linkedom-a-jsdom-alternative-53dd8f699311
ISC License
1.71k stars 82 forks source link

[feature-request] Support new Document() #289

Closed ThePlenkov closed 3 weeks ago

ThePlenkov commented 3 weeks ago

I'd like to render Dom manually with the own logic using this library.

For that purpose I'd like to do something like:

import { Document } from "linkedom";
const document = new Document();

Do you think is feasible to achieve? Thanks!

Here is the spec: https://developer.mozilla.org/en-US/docs/Web/API/Document/Document

WebReflection commented 3 weeks ago

wouldn't this be OK?

import { parseHTML } from 'linkedom';
const { window, document } = parseHTML('...');

you'll have a clean document with doctype, head, and body in there you can then enrich as you like.

ThePlenkov commented 3 weeks ago

that's a point - i don'\t have anything to parse - I'd like to build DOM document myself instead.

WebReflection commented 3 weeks ago

look closer:

parseHTML('...');

the '...' is not there as placeholder, it is the way to create an empty document where you then need to add anything you like in its head or body.

On the other hand, you can import Document and construct it https://github.com/WebReflection/linkedom/blob/main/esm/interface/document.js#L63 as long as you specify its mime type in doing so, the rest is for you to handle.

Valid mimes in here: https://github.com/WebReflection/linkedom/blob/main/esm/shared/mime.js