Skip to content

Commit 4188364

Browse files
authored
Merge pull request #237 from soc/topic/domparser
Add DOMParser
2 parents 911f30f + 2a2ab31 commit 4188364

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.scalajs.dom.experimental.domparser
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.|
5+
6+
import org.scalajs.dom.raw.{Document, HTMLDocument}
7+
8+
/**
9+
* DOMParser can parse XML or HTML source stored in a string into a DOM Document.
10+
*
11+
* MDN
12+
*/
13+
@js.native
14+
class DOMParser extends js.Object {
15+
/**
16+
* The DOMParser can also be used to parse a SVG document or a HTML document.
17+
* There are three different results possible, selected by the MIME type given.
18+
* If the MIME type is text/xml, the resulting object will be an XMLDocument,
19+
* if the MIME type is image/svg+xml, it will be an SVGDocument and
20+
* if the MIME type is text/html, it will be an HTMLDocument.
21+
*
22+
* MDN
23+
*/
24+
def parseFromString(string: String, supportedType: SupportedType): Document = js.native
25+
}
26+
27+
@js.native
28+
sealed trait SupportedType extends js.Any
29+
30+
object SupportedType {
31+
val `text/html` = "text/html".asInstanceOf[SupportedType]
32+
val `text/xml` = "text/xml".asInstanceOf[SupportedType]
33+
val `application/xml` = "application/xml".asInstanceOf[SupportedType]
34+
val `application/xhtml+xml` = "application/xhtml+xml".asInstanceOf[SupportedType]
35+
val `image/svg+xml` = "image/svg+xml".asInstanceOf[SupportedType]
36+
}

0 commit comments

Comments
 (0)