diff --git a/README.md b/README.md index 2e58fc4..0523758 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,10 @@ If only one of *init* and *row* is specified, it is interpreted as the *row* con See also [d3.csv](#csv) and [d3.tsv](#tsv). +# d3.html(input[, init]) [<>](https://github.com/d3/d3-fetch/blob/master/src/xml.js "Source") + +Fetches the file at the specified *input* URL as [text](#text) and then [parses it](https://developer.mozilla.org/docs/Web/API/DOMParser) as HTML. If *init* is specified, it is passed along to the underlying call to [fetch](https://fetch.spec.whatwg.org/#fetch-method); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed fields. + # d3.image(input[, init]) [<>](https://github.com/d3/d3-fetch/blob/master/src/image.js "Source") Fetches the image at the specified *input* URL. If *init* is specified, sets any additional properties on the image before loading. For example, to enable an anonymous [cross-origin request](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image): @@ -83,6 +87,10 @@ d3.image("https://example.com/test.png", {crossOrigin: "anonymous"}).then(functi Fetches the [JSON](http://json.org) file at the specified *input* URL. If *init* is specified, it is passed along to the underlying call to [fetch](https://fetch.spec.whatwg.org/#fetch-method); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed fields. +# d3.svg(input[, init]) [<>](https://github.com/d3/d3-fetch/blob/master/src/xml.js "Source") + +Fetches the file at the specified *input* URL as [text](#text) and then [parses it](https://developer.mozilla.org/docs/Web/API/DOMParser) as SVG. If *init* is specified, it is passed along to the underlying call to [fetch](https://fetch.spec.whatwg.org/#fetch-method); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed fields. + # d3.text(input[, init]) [<>](https://github.com/d3/d3-fetch/blob/master/src/text.js "Source") Fetches the text file at the specified *input* URL. If *init* is specified, it is passed along to the underlying call to [fetch](https://fetch.spec.whatwg.org/#fetch-method); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed fields. @@ -90,3 +98,7 @@ Fetches the text file at the specified *input* URL. If *init* is specified, it i # d3.tsv(input[, init][, row]) [<>](https://github.com/d3/d3-fetch/blob/master/src/dsv.js "Source") Equivalent to [d3.dsv](#dsv) with the tab character as the delimiter. + +# d3.xml(input[, init]) [<>](https://github.com/d3/d3-fetch/blob/master/src/xml.js "Source") + +Fetches the file at the specified *input* URL as [text](#text) and then [parses it](https://developer.mozilla.org/docs/Web/API/DOMParser) as XML. If *init* is specified, it is passed along to the underlying call to [fetch](https://fetch.spec.whatwg.org/#fetch-method); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed fields. diff --git a/index.js b/index.js index 3105f4d..bf94aa6 100644 --- a/index.js +++ b/index.js @@ -4,3 +4,4 @@ export {default as dsv, csv, tsv} from "./src/dsv"; export {default as image} from "./src/image"; export {default as json} from "./src/json"; export {default as text} from "./src/text"; +export {default as xml, html, svg} from "./src/xml"; diff --git a/src/xml.js b/src/xml.js new file mode 100644 index 0000000..6f7d1e1 --- /dev/null +++ b/src/xml.js @@ -0,0 +1,15 @@ +import text from "./text"; + +function parser(type) { + return function(input, init) { + return text(input, init).then(function(text) { + return (new DOMParser).parseFromString(text, type); + }); + }; +} + +export default parser("application/xml"); + +export var html = parser("text/html"); + +export var svg = parser("image/svg+xml");