Skip to content

Add DOMParser #237

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

Merged
merged 1 commit into from
Jul 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.scalajs.dom.experimental.domparser

import scala.scalajs.js
import scala.scalajs.js.|

import org.scalajs.dom.raw.{Document, HTMLDocument}

/**
* DOMParser can parse XML or HTML source stored in a string into a DOM Document.
*
* MDN
*/
@js.native
class DOMParser extends js.Object {
/**
* The DOMParser can also be used to parse a SVG document or a HTML document.
* There are three different results possible, selected by the MIME type given.
* If the MIME type is text/xml, the resulting object will be an XMLDocument,
* if the MIME type is image/svg+xml, it will be an SVGDocument and
* if the MIME type is text/html, it will be an HTMLDocument.
*
* MDN
*/
def parseFromString(string: String, supportedType: SupportedType): Document = js.native
}

@js.native
sealed trait SupportedType extends js.Any

object SupportedType {
val `text/html` = "text/html".asInstanceOf[SupportedType]
val `text/xml` = "text/xml".asInstanceOf[SupportedType]
val `application/xml` = "application/xml".asInstanceOf[SupportedType]
val `application/xhtml+xml` = "application/xhtml+xml".asInstanceOf[SupportedType]
val `image/svg+xml` = "image/svg+xml".asInstanceOf[SupportedType]
}