fix chrome eating whitespace
[mdref/mdref] / public / index.js
index 35587b7a2b459c848d84fa063a8e93d29dcfd44f..1d65af4382ccef907a78e6074d5de04e76fd254f 100644 (file)
@@ -117,20 +117,24 @@ $(function() {
                                return "<span class=\"constant\">";
                        }
                },
-               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);
@@ -175,12 +182,12 @@ $(function() {
                                                        $(window).scrollTop($(c).offset().top - 100);
                                                        scrolled = true;
                                                }
-                                               blink(c);
+                                               mdref.blink(c);
                                        }
                                } : function(i, c) {
                                        if (c.textContent === hash) {
                                                $(window).scrollTop($(c).offset().top - 100);
-                                               blink(c);
+                                               mdref.blink(c);
                                                return false;
                                        }
                                });