Improve README.md.

Use code syntax when possible and be consistent with the headers syntax.
This commit is contained in:
XhmikosR
2014-02-09 17:22:17 +02:00
parent 554f6cc11b
commit 8691eae14e
+23 -18
View File
@@ -1,5 +1,4 @@
FileSaver.js # FileSaver.js
============
FileSaver.js implements the HTML5 W3C `saveAs()` [FileSaver][1] interface in browsers that do FileSaver.js implements the HTML5 W3C `saveAs()` [FileSaver][1] interface in browsers that do
not natively support it. There is a [FileSaver.js demo][2] that demonstrates saving not natively support it. There is a [FileSaver.js demo][2] that demonstrates saving
@@ -12,8 +11,7 @@ sent to an external server.
Looking for `canvas.toBlob()` for saving canvases? Check out Looking for `canvas.toBlob()` for saving canvases? Check out
[canvas-toBlob.js](https://github.com/eligrey/canvas-toBlob.js) for a cross-browser implementation. [canvas-toBlob.js](https://github.com/eligrey/canvas-toBlob.js) for a cross-browser implementation.
Supported Browsers ## Supported Browsers
------------------
| Browser | Constructs as | Filenames | Max Blob Size | Dependencies | | Browser | Constructs as | Filenames | Max Blob Size | Dependencies |
| -------------- | ------------- | ------------ | ------------- | ------------ | | -------------- | ------------- | ------------ | ------------- | ------------ |
@@ -29,8 +27,11 @@ Supported Browsers
Feature detection is possible: Feature detection is possible:
try { var isFileSaverSupported = !!new Blob(); } catch(e){} ```js
try {
var isFileSaverSupported = !!new Blob();
} catch (e) {}
```
### IE < 10 ### IE < 10
@@ -44,29 +45,33 @@ Blobs may be opened instead of saved sometimes—you may have to direct your Saf
press <kbd>⌘</kbd>+<kbd>S</kbd> to save the file after it is opened. Further information is available press <kbd>⌘</kbd>+<kbd>S</kbd> to save the file after it is opened. Further information is available
[on the issue tracker](https://github.com/eligrey/FileSaver.js/issues/12). [on the issue tracker](https://github.com/eligrey/FileSaver.js/issues/12).
Syntax ## Syntax
------
FileSaver saveAs(in Blob data, in DOMString filename) ```js
FileSaver saveAs(in Blob data, in DOMString filename)
```
Examples ## Examples
--------
### Saving text ### Saving text
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"}); ```js
saveAs(blob, "hello world.txt"); var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
saveAs(blob, "hello world.txt");
```
The standard W3C File API [`Blob`][3] interface is not available in all browsers. The standard W3C File API [`Blob`][3] interface is not available in all browsers.
[Blob.js][4] is a cross-browser `Blob` implementation that solves this. [Blob.js][4] is a cross-browser `Blob` implementation that solves this.
### Saving a canvas ### Saving a canvas
var canvas = document.getElementById("my-canvas"), ctx = canvas.getContext("2d"); ```js
// draw to canvas... var canvas = document.getElementById("my-canvas"), ctx = canvas.getContext("2d");
canvas.toBlob(function(blob) { // draw to canvas...
saveAs(blob, "pretty image.png"); canvas.toBlob(function(blob) {
}); saveAs(blob, "pretty image.png");
});
```
Note: The standard HTML5 `canvas.toBlob()` method is not available in all browsers. Note: The standard HTML5 `canvas.toBlob()` method is not available in all browsers.
[canvas-toBlob.js][5] is a cross-browser `canvas.toBlob()` that polyfills this. [canvas-toBlob.js][5] is a cross-browser `canvas.toBlob()` that polyfills this.