ControlledChaos of Controlled Chaos Design
8/9/2016 - 6:58 PM

Format <pre> for whitespace preservation that uses the location of the tag as a starting point.

Format

 for whitespace preservation that uses the location of the tag as a starting point.

var pre_elements = document.getElementsByTagName('pre');

for (var i = 0; i < pre_elements.length; i++)
{
  var content = pre_elements[i].innerHTML;
  var tabs_to_remove = '';

  while (content.indexOf('\t') == '0')
    {
      tabs_to_remove += '\t';
      content = content.substring(1);
		}

  var re = new RegExp('\n' + tabs_to_remove, 'g');
		content = content.replace(re, '\n');
		pre_elements[i].outerHTML = '<pre>' + content + '</pre>';
}

Format <pre> Tag Whitespace

Format <pre> for whitespace preservation that uses the location of the tag as a starting point.