Advertisement
mariammrf_

Change single quotes to double quotes

Jan 14th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. walk(document.body);
  2. function walk(node)
  3. {
  4.     // I stole this function from here:
  5.     // http://is.gd/mwZp7E
  6.    
  7.     var child, next;
  8.  
  9.     switch ( node.nodeType )  
  10.     {
  11.         case 1:  // Element
  12.         case 9:  // Document
  13.         case 11: // Document fragment
  14.             child = node.firstChild;
  15.             while ( child )
  16.             {
  17.                 next = child.nextSibling;
  18.                 walk(child);
  19.                 child = next;
  20.             }
  21.             break;
  22.  
  23.         case 3: // Text node
  24.             handleText(node);
  25.             break;
  26.     }
  27. }
  28.  
  29. function handleText(textNode)
  30. {
  31.     var v = textNode.nodeValue;
  32.     v = v.replace(/( ')/g, ' "');
  33.     v = v.replace(/(')(?![a-z])/g, '"');
  34.  
  35.     textNode.nodeValue = v;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement