+ // End code mode
+ if (codeMode) {
+ out.push('</pre>');
+ out.push('<p>');
+ codeMode = false;
+ }
+ return;
+ }
+
+ // Sometimes I wish more languages had Perl's bistable .. operator.
+ if (githubCodeMode) {
+ if (l == '```') {
+ out.push('</pre>');
+ out.push('<p>');
+ githubCodeMode = false;
+ } else {
+ // Sanitize HTML input
+ l = l.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
+ out.push(l + "\n");
+ }
+ return;
+ } else {
+ if (l == '```') {
+ out.push('<pre>');
+ githubCodeMode = true;
+ return;
+ }
+ }
+
+ // Create a code block when lines begin with at least four spaces
+ if (l.substr(0, 4) == ' ') {
+ if (!codeMode) {
+ out.push('<pre>');
+ codeMode = true;
+ }
+ // Sanitize HTML input
+ l = l.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
+ out.push(l.substr(4) + "\n");