"+s(o[2],!0)+"
";continue}if(o=this.rules.br.exec(e)){e=e.substring(o[0].length),t+=""+this.token.text+"
\n";case"table":var t="",n,r,i,o,u;t+="\n\n"+t+"\n";case"list_start":var a=this.token.ordered?"ol":"ul",t="";while(this.next().type!=="list_end")t+=this.tok();return"<"+a+">\n"+t+""+a+">\n";case"list_item_start":var t="";while(this.next().type!=="list_item_end")t+=this.token.type==="text"?this.parseText():this.tok();return"
"+this.inline.output(this.token.text)+"
\n";case"text":return""+this.parseText()+"
\n"}},u.exec=u,f.options=f.setOptions=function(e){return f.defaults=e,f},f.defaults={gfm:!0,tables:!0,breaks:!1,pedantic:!1,sanitize:!1,silent:!1,highlight:null},f.Parser=i,f.parser=i.parse,f.Lexer=t,f.lexer=t.lex,f.InlineLexer=r,f.inlineLexer=r.output,f.parse=f,typeof module!="undefined"?module.exports=f:typeof define=="function"&&define.amd?define(function(){return f}):this.marked=f}.call(function(){return this||(typeof window!="undefined"?window:global)}()); \ No newline at end of file + */(function(e,t){function n(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])}function r(e,t){for(var n in t)t.hasOwnProperty(n)&&(e.style[n]=t[n])}function i(t,n){var r=t,i=null;return e.getComputedStyle?i=document.defaultView.getComputedStyle(r,null).getPropertyValue(n):r.currentStyle&&(i=r.currentStyle[n]),i}function s(e,t,n){var s={},o;if(t==="save"){for(o in n)n.hasOwnProperty(o)&&(s[o]=i(e,o));r(e,n)}else t==="apply"&&r(e,n);return s}function o(e){var t=parseInt(i(e,"border-left-width"),10)+parseInt(i(e,"border-right-width"),10),n=parseInt(i(e,"padding-left"),10)+parseInt(i(e,"padding-right"),10),r=e.offsetWidth,s;return isNaN(t)&&(t=0),s=t+n+r,s}function u(e){var t=parseInt(i(e,"border-top-width"),10)+parseInt(i(e,"border-bottom-width"),10),n=parseInt(i(e,"padding-top"),10)+parseInt(i(e,"padding-bottom"),10),r=e.offsetHeight,s;return isNaN(t)&&(t=0),s=t+n+r,s}function a(e,t,r){r=r||"";var i=t.getElementsByTagName("head")[0],s=t.createElement("link");n(s,{type:"text/css",id:r,rel:"stylesheet",href:e,name:e,media:"screen"}),i.appendChild(s)}function f(e,t,n){e.className=e.className.replace(t,n)}function l(e){return e.contentDocument||e.contentWindow.document}function c(e){var t;return typeof document.body.innerText=="string"?t=e.innerText:(t=e.innerHTML.replace(/"+s(o[2],!0)+"
";continue}if(o=this.rules.br.exec(e)){e=e.substring(o[0].length),t+=""+this.token.text+"
\n";case"table":var t="",n,r,i,o,u;t+="\n\n"+t+"\n";case"list_start":var a=this.token.ordered?"ol":"ul",t="";while(this.next().type!=="list_end")t+=this.tok();return"<"+a+">\n"+t+""+a+">\n";case"list_item_start":var t="";while(this.next().type!=="list_item_end")t+=this.token.type==="text"?this.parseText():this.tok();return"
"+this.inline.output(this.token.text)+"
\n";case"text":return""+this.parseText()+"
\n"}},u.exec=u,f.options=f.setOptions=function(e){return f.defaults=e,f},f.defaults={gfm:!0,tables:!0,breaks:!1,pedantic:!1,sanitize:!1,silent:!1,highlight:null},f.Parser=i,f.parser=i.parse,f.Lexer=t,f.lexer=t.lex,f.InlineLexer=r,f.inlineLexer=r.output,f.parse=f,typeof module!="undefined"?module.exports=f:typeof define=="function"&&define.amd?define(function(){return f}):this.marked=f}.call(function(){return this||(typeof window!="undefined"?window:global)}()); \ No newline at end of file diff --git a/index.html b/index.html index fd3b19d..ead9123 100644 --- a/index.html +++ b/index.html @@ -279,6 +279,7 @@syncWithServerBtn.onclick = function () {
diff --git a/src/editor.js b/src/editor.js
index 020462a..84ffd90 100644
--- a/src/editor.js
+++ b/src/editor.js
@@ -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:
diff --git a/test/test.exportFile.js b/test/test.exportFile.js
index cabf468..f50482f 100644
--- a/test/test.exportFile.js
+++ b/test/test.exportFile.js
@@ -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('foo
\nbar
\n');