- // Sanitize HTML input
- record.data = record.data.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
+ var lines = record.data.split(/\r?\n/);
+ if (lines[lines.length - 1] == '')
+ lines.pop();
+
+ var out = ['<p>'];
+ var endpush = null;
+ var listMode = false;
+ lines.each(function(l) {
+ if (l == '') {
+ if (out[out.length - 1] == '<br>') {
+ out[out.length - 1] = '<p>';
+ }
+ if (out[out.length - 1] == '</li>') {
+ out.push('</ul>');
+ out.push('<p>');
+ listMode = false;
+ }
+ return;
+ }
+
+ if (l[0] == '>') {
+ var pi = out.lastIndexOf('<p>');
+ if (pi != -1) {
+ out[pi] = '<p class="quote">';
+ l = l.replace(/^>\s*/, '');
+ }
+ }
+ if (l[0] == '*') {
+ if (!listMode) {
+ var pi = out.lastIndexOf('<p>');
+ out[pi] = '<ul>';
+ listMode = true;
+ }
+ l = l.replace(/^\*\s*/, '');
+ out.push('<li>');
+ endpush = '</li>';
+ }
+ if (l[0] == '=') {
+ var m = l.match(/^(=+)/);
+ var depth = m[1].length;
+ if (depth <= 5) {
+ l = l.replace(/^=+\s*/, '').replace(/\s*=+$/, '');
+ out.push('<h' + depth + '>');
+ endpush = '</h' + depth + '>';
+ }
+ }
+
+ // Sanitize HTML input
+ l = l.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');