From a2e83586913b88611a6309428b0d4c3e6f5188e9 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 17 Apr 2014 16:06:48 +0200 Subject: [PATCH] fix chrome eating whitespace --- public/index.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/public/index.js b/public/index.js index 62ccba6..1d65af4 100644 --- a/public/index.js +++ b/public/index.js @@ -117,20 +117,24 @@ $(function() { return ""; } }, - node: function node(s, nn) { - // mdref.log("node", s); - var t; - if ((t = mdref.type(s, nn))) { - return $(t).text(s); - } - return document.createTextNode(s); - }, wrap: function wrap(n, nn) { var $n = $(n) var a = []; $n.text().split(/([^a-zA-Z0-9_\\\$:]+)/).forEach(function(v) { - a.push(mdref.node(v, nn)); + var t; + + if ((t = mdref.type(v, nn))) { + a.push($(t).text(v)); + } else if (a.length && a[a.length-1].nodeName === "#text") { + /* if we already have a text node and the next is also gonna be a text + * node, then join them, becuase chrome v30+ or something eats whitespace + * for breakfast, lunch and dinner! + */ + a[a.length-1].textContent += v; + } else { + a.push(document.createTextNode(v)); + } }); $n.replaceWith(a); }, @@ -142,6 +146,9 @@ $(function() { case "A": case "BR": case "HR": + case "EM": + case "CODE": + case "SPAN": break; case "#text": mdref.wrap(n, e.nodeName); -- 2.30.2