summaryrefslogtreecommitdiff
path: root/js/lib/inlines.js
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-01-09 14:30:49 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-01-09 14:31:16 -0800
commit3c68dcac2d30616904840c52d359653ba1f746b4 (patch)
tree4713867b156a27f3e3d52b2436cd40da2a07f9b1 /js/lib/inlines.js
parent9d005eab33db7b31edca49982398c666ccc27567 (diff)
Simplified reMain, with AST manipulation for 2-space hardbreak.
Small performance improvement.
Diffstat (limited to 'js/lib/inlines.js')
-rw-r--r--js/lib/inlines.js17
1 files changed, 13 insertions, 4 deletions
diff --git a/js/lib/inlines.js b/js/lib/inlines.js
index 5cec93b..ff3ffde 100644
--- a/js/lib/inlines.js
+++ b/js/lib/inlines.js
@@ -71,7 +71,7 @@ var reEntity = new RegExp(ENTITY, 'gi');
// Matches a character with a special meaning in markdown,
// or a string of non-special characters. Note: we match
// clumps of _ or * or `, because they need to be handled in groups.
-var reMain = /^(?:[_*`\n]+|[\[\]\\!<&*_]|(?: *[^\n `\[\]\\!<&*_]+)+|[ \n]+)/m;
+var reMain = /^(?:[_*`\n]+|[\[\]\\!<&*_]|[^\n`\[\]\\!<&*_]+)/m;
// Replace entities and backslash escapes with literal characters.
var unescapeString = function(s) {
@@ -670,10 +670,19 @@ var parseString = function(block) {
// line break; otherwise a soft line break.
var parseNewline = function(block) {
"use strict";
- var m = this.match(/^ *\n/);
+ var m = this.match(/^\n/);
if (m) {
- var node = new Node(m.length > 2 ? 'Hardbreak' : 'Softbreak');
- block.appendChild(node);
+ // check previous node for trailing spaces
+ var lastc = block.lastChild;
+ if (lastc && lastc.t === 'Text') {
+ var sps = / *$/.exec(lastc.c)[0].length;
+ if (sps > 0) {
+ lastc.c = lastc.c.replace(/ *$/,'');
+ }
+ block.appendChild(new Node(sps >= 2 ? 'Hardbreak' : 'Softbreak'));
+ } else {
+ block.appendChild(new Node('Softbreak'));
+ }
return true;
} else {
return false;