Comments (6)
I had need of something like this
https://github.com/nrkn/dom-treeadapter/
I'm not actually using it with parse5 though - I've adopted the parse5 TreeAdapter interface throughout another project and I'm using it to map between two different DOM structures. Here's the mapper I'm using:
https://github.com/nrkn/treeadapter-mapper
from parse5.
from parse5.
Adaptor for jsdom, xmldom, libxml-dom, …
In case you wanted to suggest jsdom as an alternative: sure, it can provide similar functionality, but the fact that the latest version requires io.js makes me reluctant to use it. And parsing to jsdom just so you can import the node into some other DOM implementation you're working with doesn't look attractive either. On the other hand, another tree adaptor would be a fairly easy affair. Should I make this a pull request?
from parse5.
Well, seems like I don't quite understand what you want. Can you illiustrate it via some code snippets, please?
from parse5.
What I had in mind was something like this:
var parser = new Parser(new DomTreeAdapter(new xmldom.DOMImplementation()));
where DomTreeAdapter
would be a new class shipped with parse5, and its constructor argument could be any object satisfying the DOMImplementation
specification. But I now had a closer look and realized that on the one hand, libxml-dom apparently doesn't offer such a DOM implementation class, so the number of users would be rather small.
On the other hand, parse5 does object creation significantly different from what the DOM specs envision, so the effort to make things work out would be considerable. In particular, one would have to know the name (and namespace) of the root element before creating the document, and one would have to pass the document as an adapter function argument whenever constructing new elements. Probably not worth the effort just now. I thought this would be simpler, thus my suggestion.
Feel free to close if you don't want to pursue this either.
from parse5.
DOM has a much more complicated connection with the HTML parser than this. I suggest you to keep an eye on JSDOM project, which is the most complete and spec-compliant pure-js DOM implementation at the moment.
from parse5.
Related Issues (20)
- Expose createTextNode() on default tree adapter HOT 3
- Custom single closing tag can`t be parsed correctly HOT 1
- Rewriter trigger the "text" event even after the write callback is executed HOT 10
- Node types don't appear to be exported in an ergonomic way HOT 4
- Enable Keeping Attribute Name Casing HOT 9
- Adding config that allow for the use of self close tags HOT 1
- Failed to parse source map from file: Error: ENOENT: no such file or directory HOT 18
- parse5-html-rewriting-stream fails on file > 128kByte HOT 2
- Failed to parse source map ... HOT 3
- Package subpath './lib/parser/index.js' is not defined by "exports" HOT 2
- Incorrect handling of CDATA sections HOT 1
- browserify fails for parse5 HOT 1
- node_modules/parse5/dist/index.d.ts:1:15 - error TS1005: ',' expected. HOT 4
- Type definitions are not properly generated and typescript compile fails HOT 2
- Wrong HTML string when reading from a file with encoding utf8 with bom HOT 1
- Parsing messes up when given a utf-8 input with a BOM HOT 12
- The detachNode has not been called HOT 1
- Outlook VML statements become commented HOT 1
- Noframes tag not parsed according to specification when in body
- Migrate some or most methods of Tokenizer and Parser to `protected`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parse5.