Skip to content

Commit

Permalink
Ticket OscarGodson#237 json export type
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Beingessner committed Jun 11, 2013
1 parent 5e16903 commit 7d17092
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ Returns the plain text of the file by default, or if given a type will return th

* text (default)
* html
* json (includes metadata)
* raw (warning: this is browser specific!)

```javascript
Expand Down
3 changes: 3 additions & 0 deletions epiceditor/js/epiceditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,9 @@
return self.settings.parser(content);
case 'text':
return _sanitizeRawContent(content);
case 'json':
file.content = _sanitizeRawContent(file.content);
return JSON.stringify(file);
case 'raw':
return content;
default:
Expand Down
2 changes: 1 addition & 1 deletion epiceditor/js/epiceditor.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ <h3>exportFile([<em>filename</em>],[<em>type</em>])</h3>
<ul>
<li>text (default)</li>
<li>html</li>
<li>json (includes metadata)</li>
<li>raw (warning: this is browser specific!)</li>
</ul>
<pre><code class="lang-javascript">syncWithServerBtn.onclick = function () {
Expand Down
3 changes: 3 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,9 @@
return self.settings.parser(content);
case 'text':
return _sanitizeRawContent(content);
case 'json':
file.content = _sanitizeRawContent(file.content);
return JSON.stringify(file);
case 'raw':
return content;
default:
Expand Down
10 changes: 10 additions & 0 deletions test/test.exportFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ describe('.exportFile([fileName], [type])', function () {
expect(contents).to.match(/#foo\r?\n\r?\n##bar/);
});

it('should export to json', function () {
var obj;
contents = editor.exportFile(null, 'json');
expect((typeof contents)).to.be('string');
obj = JSON.parse(contents);
expect(obj.content).to.match(/#foo\r?\n\r?\n##bar/);
expect(obj).to.have.property('created');
expect(obj).to.have.property('modified');
})

it('should export the current file as HTML with a null parameter as it\'s first', function () {
contents = editor.exportFile(null, 'html');
expect(contents).to.be('<h1>foo</h1>\n<h2>bar</h2>\n');
Expand Down

0 comments on commit 7d17092

Please sign in to comment.