-
-
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
Conversation
Can't this be added directly to |
Only |
this belongs in |
lib/js/dom.nim
Outdated
func newDOMParser*(): DOMParser {.importcpp: "(new DOMParser())".} | ||
## DOM Parser constructor. | ||
|
||
func parseFromString*(this: DOMParser; str: cstring; mimeType = "text/html".cstring): Document {.importcpp.} |
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.
-
same comment as in your
jsfetch
PR, use an enum since there is a finite set of acceptable values for mimeType, see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser. This makes is impossible to misuse that argument, is self documenting, etc... Yes, this requires a helper importcpp procparseFromStringImpl
-
don't provide default arg for
mimeType
since that's what's done in https://developer.mozilla.org/en-US/docs/Web/API/DOMParser (This method has 2 parameters (both required):
)
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.
or we can just remove the default mimeType
and keep it barebones. JS is a wild place and things can change really fast. We should just provide a barebones wrapper and call it a day.
lib/js/dom.nim
Outdated
@@ -985,6 +985,16 @@ type | |||
once*: bool | |||
passive*: bool | |||
|
|||
since (1, 3): | |||
type DOMParser* = ref object ## \ |
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.
Bikeshedding: Should this be DomParser
(and newDomParser
)? Quoting NEP-1:
In the age of HTTP, HTML, FTP, TCP, IP, UTF, WWW it is foolish to pretend these are somewhat special words requiring all uppercase. Instead treat them as what they are: Real words. So it's parseUrl rather than parseURL, checkHttpHeader instead of checkHTTPHeader etc.
Don't know if DOM counts on the same level as HTTP and HTML but I don't really know if the "level" matters either.
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.
Yeah, it's DomParser and newDomParser indeed.
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.
Looks good, but see my and @hlaaftana's comment.
@@ -9,7 +9,7 @@ | |||
|
|||
## Declaration of the Document Object Model for the `JavaScript backend | |||
## <backends.html#backends-the-javascript-target>`_. | |||
|
|||
include "system/inclrtl" |
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.
lib/js/dom.nim
Outdated
|
||
|
||
since (1, 3): | ||
func newDOMParser*(): DOMParser {.importcpp: "(new DOMParser())".} |
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.
this doesn't work, you must've pasted from a webpage and introduced an invisible symbol (see cat -e). you should make sure examples work
also, you should remove outer parens
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.
This should be .importjs: "new DOMParser()"
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.
#13891 (comment) (Doc Test exit non-zero)
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 comment
The 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:
type MimeTypeDom = enum
textHtml = "text/html" etc
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.
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 comment
The 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 comment
The 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:
let a = prsr.parseFromString("<html>...</html>".cstring, $textHtml)
(but not sure what's the difference with fetch
API case https://github.com/nim-lang/Nim/pull/12531/files#r403861811
So what, please use enums.
)
@@ -9,7 +9,7 @@ | |||
|
|||
## Declaration of the Document Object Model for the `JavaScript backend | |||
## <backends.html#backends-the-javascript-target>`_. | |||
|
|||
include "system/inclrtl" |
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.
Without Thanks. 🙂 |
/cc @dom96 |
And what would be the content of the RFC? "I don't understand the -std=c99 switch"? Opinions are valuable if you shaped them after you understood the problem... Bringing it up again and again wastes my time. |
jsdomparser
the DOM Parser for JavaScript target.