docs: function HTMLOfENML(text, resources){
  
      resources = resources || [];
  
      var resource_map = {}
      resources.forEach(function(resource){
  
        var hex = [].map.call( resource.data.bodyHash, 
          function(v) { str = v.toString(16); 
          return str.length < 2 ? "0" + str : str;  }).join("");
  
        resource_map[hex] = resource;
      })
  
      var writer = new XMLWriter();
      var parser = new SaxParser(function(cb) {
  
        var mediaTagStarted = false;
        var linkTagStarted = false;
        var linkTitle;
  
        cb.onStartElementNS(function(elem, attrs, prefix, uri, namespaces) {
  
          if(elem == 'en-note'){
            writer.startElement('html');
            writer.startElement('head');
  
            writer.startElement('meta');
            writer.writeAttribute('http-equiv', 'Content-Type');
            writer.writeAttribute('content', 'text/html; charset=UTF-8');
            writer.endElement();
  
            writer.endElement();
  
            writer.startElement('body');
            if(!(attrs && attrs[0] && attrs[0][0] && attrs[0][0] === 'style'))
              writer.writeAttribute('style', 'word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;');
          } else if(elem == 'en-todo'){
  
            writer.startElement('input');
            writer.writeAttribute('type', 'checkbox');
  
          } else if(elem == 'en-media'){
  
            var type = null;
            var hash = null;
            var width = 0;
            var height = 0;
  
            if(attrs) attrs.forEach(function(attr) {
              if(attr[0] == 'type') type = attr[1];
              if(attr[0] == 'hash') hash = attr[1];
              if(attr[0] == 'width') width = attr[1];
              if(attr[0] == 'height') height = attr[1];
            });
  
            var resource = resource_map[hash];
            
            if(!resource) return;
            var resourceTitle = resource.title || '';
            
            if(type.match('image')) {
  
              writer.startElement('img');
              writer.writeAttribute('title', resourceTitle);
  
            } else if(type.match('audio')) {
              
              
              writer.writeElement('p', resourceTitle);
              writer.startElement('audio');
              writer.writeAttribute('controls', '');
              writer.text('Your browser does not support the audio tag.');
              writer.startElement('source');
              mediaTagStarted = true;
  
            } else if(type.match('video')) {
              writer.writeElement('p', resourceTitle);
              writer.startElement('video');
              writer.writeAttribute('controls', '');
              writer.text('Your browser does not support the video tag.');
              writer.startElement('source');
              mediaTagStarted = true;
            } else {
              writer.startElement('a');
              linkTagStarted = true;
              linkTitle = resourceTitle;
            }
            
            if(resource.data.body) {
              var b64encoded = base64ArrayBuffer(resource.data.body);
              var src = 'data:'+type+';base64,'+b64encoded;
              writer.writeAttribute('src', src)
            }
  
            if(width) writer.writeAttribute ('width', width);
            if(height) writer.writeAttribute('height', height);
  
          } else {
            writer.startElement(elem);
          }
  
          if(attrs) attrs.forEach(function(attr) {
            writer.writeAttribute(attr[0], attr[1]);
          });
  
        });
        cb.onEndElementNS(function(elem, prefix, uri) {
  
          if(elem == 'en-note'){
            writer.endElement(); //body
            writer.endElement(); //html
          }
          else if(elem == 'en-todo'){
  
          }
          else if(elem == 'en-media'){
            if(mediaTagStarted) {
              writer.endElement(); // source
              writer.endElement(); // audio or video
              writer.writeElement('br', '');
              mediaTagStarted = false;
  
            } else if(linkTagStarted) {
              writer.text(linkTitle);
              writer.endElement(); // a
              linkTagStarted = false;
  
            } else {
              writer.endElement();
            }
  
          } else {
  
            writer.endElement();
          }
        });
        cb.onCharacters(function(chars) {
          writer.text(chars);
        });
  
      });
  
      parser.parseString(text);
      return writer.toString();
  
    }