code: function render(val) {
          // This only needs to be done when the user is in preview mode
          if (!$preview.is(":visible")) {
              return;
          }
  
          if (!val) {
              val = editor.getSession().getValue();
          }
          // Sanitize the content
          val = html_sanitize(val, urlX, idX);
  
          switch (renderMode) {
          case "plain":
              editor.getSession().setMode(textMode);
              val = val.replace(/\r\n|\r|\n/g, "<br />"); // Newlines
              val = val.replace(/  /g, "&nbsp;&nbsp;"); // Whitespaces
              $('#paper').html("<p></p>" + val);
              $('#import-button').attr("title", strings['import-button-title-plain']);
              $('#export-text').text(strings['export-text-plain']);
              break;
  
          case "textile":
              editor.getSession().setMode(textileMode);
              $('#paper').html(textile(val));
              $('#import-button').attr("title", strings['import-button-title-textile']);
              $('#export-text').text(strings['export-text-textile']);
              break;
  
          case "markdown":
              editor.getSession().setMode(markdownMode);
              $('#paper').html(markdownConverter.makeHtml(val));
              $('#import-button').attr("title", strings['import-button-title-markdown']);
              $('#export-text').text(strings['export-text-markdown']);
              break;
  
          case "latex":
              break;
          }
      }
docs: ////////////////////////////////////////////////////////////////////////////////////////////////// /* Parse written content and update the preview panel