Skip to content

Support JSDOM #3

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

Closed
tripodsan opened this issue May 29, 2019 · 10 comments · Fixed by #4
Closed

Support JSDOM #3

tripodsan opened this issue May 29, 2019 · 10 comments · Fixed by #4
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have

Comments

@tripodsan
Copy link

Subject of the feature

When running in nodejs, the global document is not available. There is no way to pass in the JSDOM document or document implementation.

Problem

Without this feature, this util is useless in nodejs.

Expected behaviour

It should be possible to pass in the document via options eg:

toDOM(root, { document: new JSDOM().window.document });

Alternatives

non so far detected.

@wooorm
Copy link
Member

wooorm commented May 29, 2019

Good idea! Can you work on a PR?

@tripodsan
Copy link
Author

Can you work on a PR?

sure.

@wooorm
Copy link
Member

wooorm commented May 29, 2019

Great!
I do wonder if using hast/rehype with jsdom kinda defeats the purpose a bit. They’re kind of alternatives to each other, and both JSDOM and rehype-parse work through parse5. But this utility is much smaller if there’s access to browser APIs.

@tripodsan
Copy link
Author

we're using it together with remark, that turns markdown into mdast. which can be turned into hast. I want to use jsdom in the end, and currently there is no good mdast-to-dom util yet, as far as I know.

@wooorm
Copy link
Member

wooorm commented May 29, 2019

You’re right that this is the way to go, and it’s not duplicate work if you’re not using rehype-parse. But I’m wondering why you’d want JSDOM in the end?

wooorm added a commit that referenced this issue May 30, 2019
@wooorm
Copy link
Member

wooorm commented May 30, 2019

I made a PR!

@wooorm wooorm closed this as completed in #4 May 31, 2019
wooorm added a commit that referenced this issue May 31, 2019
Closes GH-3.
Closes GH-4.

Reviewed-by: Keith McKnight <[email protected]>
Reviewed-by: Christian Murphy <[email protected]>
@trieloff
Copy link

trieloff commented Jun 6, 2019

But I’m wondering why you’d want JSDOM in the end?

(@tripodsan and I are working on the same project) our target audience are web developers who are very familiar with the DOM APIs so that the congruence of working in MDAST vs HAST is not as valuable as giving them a familiar tool to tweak the HTML output of the process.

@wooorm
Copy link
Member

wooorm commented Jun 6, 2019

Thanks for the info! That makes more sense!

I believe you could also go hast -> string, string -> jsdom, I don’t think there are disadvantages of that.

In the future we could also for example set position on DOM nodes, in this library, that would be a cool advantage: a lint rule that checks the DOM and warns about something going on at a specific place in a markdown file!

@trieloff
Copy link

trieloff commented Jun 6, 2019

We will probably need position at some point in the DOM, as we will build an editor that should synchronize scroll position, cursor position (and if possible, select ranges)

@tripodsan
Copy link
Author

I believe you could also go hast -> string, string -> jsdom,

yes. that's what we did before. but it was too slow :-)

We might also need support for type: 'raw' soon. those nodes are generated by remark, when you have inline HTML in the markdown. I will provide a new issue and PR eventually :-)

@wooorm wooorm added ⛵️ status/released 🗄 area/interface This affects the public interface 🦋 type/enhancement This is great to have 🧒 semver/minor This is backwards-compatible change labels Aug 11, 2019
@wooorm wooorm added the 💪 phase/solved Post is done label Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have
Development

Successfully merging a pull request may close this issue.

3 participants