-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add jsdomparser #13920
Add jsdomparser #13920
Changes from all commits
48f471e
87f8738
6f89c3d
d381256
ea65e27
bb04479
4f3e290
6172d73
92f5394
2c2739e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
## Declaration of the Document Object Model for the `JavaScript backend | ||
## <backends.html#backends-the-javascript-target>`_. | ||
|
||
include "system/inclrtl" | ||
when not defined(js) and not defined(Nimdoc): | ||
{.error: "This module only works on the JavaScript platform".} | ||
|
||
|
@@ -985,6 +985,16 @@ type | |
once*: bool | ||
passive*: bool | ||
|
||
since (1, 3): | ||
type DomParser* = ref object ## \ | ||
## DOM Parser object (defined on browser only, may not be on NodeJS). | ||
## * https://developer.mozilla.org/en-US/docs/Web/API/DOMParser | ||
## | ||
## .. code-block:: nim | ||
## let prsr = newDomParser() | ||
## discard prsr.parseFromString("<html><marquee>Hello World</marquee></html>".cstring, "text/html".cstring) | ||
|
||
|
||
proc id*(n: Node): cstring {.importcpp: "#.id", nodecl.} | ||
proc `id=`*(n: Node; x: cstring) {.importcpp: "#.id = #", nodecl.} | ||
proc class*(n: Node): cstring {.importcpp: "#.className", nodecl.} | ||
|
@@ -1297,3 +1307,10 @@ proc offsetHeight*(e: Node): int {.importcpp: "#.offsetHeight", nodecl.} | |
proc offsetWidth*(e: Node): int {.importcpp: "#.offsetWidth", nodecl.} | ||
proc offsetTop*(e: Node): int {.importcpp: "#.offsetTop", nodecl.} | ||
proc offsetLeft*(e: Node): int {.importcpp: "#.offsetLeft", nodecl.} | ||
|
||
since (1, 3): | ||
func newDomParser*(): DOMParser {.importcpp: "(new DOMParser())".} | ||
## DOM Parser constructor. | ||
|
||
func parseFromString*(this: DOMParser; str: cstring; mimeType: cstring): Document {.importcpp.} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still meh on that; at least provide an enum to make life easier for users eg:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't. JS grows relatively fast and change really quickly, so we should not spent too much time chasing these things. Different browsers might support more MIME types, and it's not really our place to dictate how to use an API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with alaviss on this point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fine, we can later introduce type MimeTypes = enum
textHtml = "text/html".cstring
# etc and use it as: (but not sure what's the difference with
|
||
## Parse from string to `Document`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this being added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not needed and should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it includes
since
but you shouldn't have to manually include it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to otherwise you get CT error; but if we merged #11865 we could import it instead of including it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once again putting it out there that I consider this
since
thing to be a waste of time.