/* global define */
define(["underscore","q","markdown-it","prism/bundle","markdown-it-san","markdown-it-hash","markdown-it-math","markdown-it-imsize","modules/markdown/libs/markdown-it-task","modules/markdown/libs/markdown-it-file"],function(e,n,t,s,r,i,a,o,u,l){"use strict";function c(){this.md=new t({html:!0,xhtmlOut:!0,breaks:!0,linkify:!0,highlight:function(e,n){return s.languages[n]?s.highlight(e,s.languages[n]):""}}),this.configure()}return e.extend(c.prototype,{objectURLs:{},configure:function(){this.md.use(r).use(o).use(a,{inlineOpen:"$",inlineClose:"$",blockOpen:"$$",blockClose:"$$",renderingOptions:{},inlineRenderer:function(e){return'<span class="math inline">$'+e+"$</span>"},blockRenderer:function(e){return'<div class="math block">$$'+e+"$$</div>"}}).use(i,{hashtagRegExp:"[\\u0021-\\uFFFF\\w\\-]+|<3",preceding:"^|\\s"}).use(u.init).use(l.init),this.md.renderer.rules.table_open=function(){return'<div class="table-responsive"><table>'},this.md.renderer.rules.table_close=function(){return"</table></div>"},this.md.renderer.rules.hashtag_open=function(e,n,t,s){var r=e[n].content.toLowerCase();return s&&(s.tags=s.tags||[],s.tags.push(r)),'<a href="#/notes/f/tag/q/'+r+'" class="label label-default">'}},render:function(t){var s={modelData:t,objectURLs:this.objectURLs};return t.id&&l.revokeURLs(this.objectURLs,t),new n(this.md.render(e.unescape(t.content),s))},taskToggle:function(n){return n.content=e.unescape(n.content),n.content=u.toggle(n),this.parse(n.content).then(function(t){return e.extend({content:n.content},t)})},parse:function(t){var s={};return new n(this.md.render(e.unescape(t),s)).then(function(){return s.tags=s.tags?e.uniq(s.tags):[],s.files=s.files?e.uniq(s.files):[],s.taskAll=s.tasks?s.tasks.length:0,s})}}),c});