Automatically generate Dart wrappers and doc from MDN #570
-
Hi, I am a Dart developer and I would like to create a JS package for Dart devs to use. @JS()
library window;
@JS()
abstract class HtmlElement {}
@JS()
abstract class HtmlDocument {
external HtmlElement? getElemenyById(String buf);
}
@JS()
external HtmlDocument get document; The above snippet is a Dart interface to use the window object along with document and getElementById. Is this ok? |
Beta Was this translation helpful? Give feedback.
Replies: 0 comments 11 replies
-
See https://developer.mozilla.org/en-US/docs/MDN/Tools/Unsupported_GET_API for info about the only thing available. For example, to get a JSON representation of the https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement article, you can using https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/index.json
Yes, it’s OK to scrape the production site to get either that JSON data or the HTML source, or any other data you want to get. That said, you don’t actually need to remotely scrape the production site — you can instead run a “preview server” locally to get what you need. The details are in step 6 of https://github.com/mdn/content/blob/main/README.md#more-substantial-changes — but the gist of it is, you clone this repo, and then run this sequence of commands: # Switch to a separate terminal.
cd ~/repos/mdn/content
yarn
yarn start That will start a web server on your local system, accessible at http://localhost:5000. So if you want to get the JSON data for the |
Beta Was this translation helpful? Give feedback.
-
This is just great, thanks!
how can I avoid shutting the server after an exception like that? |
Beta Was this translation helpful? Give feedback.
-
was able to avoid the exception by checking if there is an dataURL in compatibility at the body info. I can't seem to be able to automatically identify the return values or methods and getters. |
Beta Was this translation helpful? Give feedback.
-
I thought I'd point out what rather than scrapping MDN you'd probably be better off using the official docs for each API. Most of them have a machine readable IDL file or section(s) that is/are specifically designed for generating code. In fact most of the browsers themselves read those files to generate some of the code in the browser itself. I don't know if the IDL files are sitting somewhere or just buried in the specs but for example the WebGL2 IDL is here -- it says it's scrapped from the spec. |
Beta Was this translation helpful? Give feedback.
-
hello Checkout out how nice the MediaStream file got with the docs: https://github.com/jodinathan/js_bindings/blob/main/lib/bindings/mediacapture_streams.dart thanks a lot for the info, was very helpful |
Beta Was this translation helpful? Give feedback.
See https://developer.mozilla.org/en-US/docs/MDN/Tools/Unsupported_GET_API for info about the only thing available.
For example, to get a JSON representation of the https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement article, you can using https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/index.json
Yes, it’s OK to scrape the production site to get either that JSON data or the HTML source, or any other data you want to get.
That said, you don’t actually need to remotely scrape the production site — you can instead run a “preview server” locally to get what you need. The details are in step 6 of https://github.com/mdn/content/blob/main/README.md#more-subst…