Skip to content
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

Merged
merged 10 commits into from
Apr 13, 2020
Merged
Next Next commit
Add jsdomparser
juancarlospaco committed Apr 8, 2020
commit 48f471e11eb676222ee0303a56e9876829a0c5a2
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

## Standard library additions and changes

- Add `jsdomparser` the [DOM Parser](https://developer.mozilla.org/en-US/docs/Web/API/DOMParser) for JavaScript target.

## Language changes

23 changes: 23 additions & 0 deletions lib/js/jsdomparser.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## DOM Parser for JavaScript target
## ================================
##
## * 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)

include "system/inclrtl"

since (1, 3):
from dom import Document
export Document

type DOMParser* = ref object ## \
## DOM Parser object (defined on browser only, may not be on NodeJS).

func newDOMParser*(): DOMParser {.importcpp: "(new DOMParser()​​)".}
## DOM Parser constructor.

func parseFromString*(this: DOMParser; str: cstring, mimeType = "text/html".cstring): Document {.importcpp.}
## Parse from string to Document.