According to the CSS 2.1 specifications, tabs (U+0009) are displayed as a horizontal shift aligning the next glyph with the tab stop. These tab stops occur at intervals that are multiples of 8 times the width of a space (U+0020) in the block's font.
CSS3 Text echoes similar rules for handling tabs.
In HTML 4.01, the PRE element interprets the horizontal tab character (decimal 9) as the minimum number of spaces needed to line characters up along tab stops every 8 characters. However, it is not recommended to use horizontal tabs in preformatted text due to potential misalignment issues when editing and setting different tab-spacing values.
To avoid problems with leading tabs, simply replace them with spaces.
/* Multiplication using Russian Peasant method */
String.prototype.repeat = function (n) {
if (n<1) return '';
var accum = '', c=this;
for (; n; n >>=1) {
if (1&n) accum += c;
c += c;
}
return accum;
}
String.prototype.untabify = function(tabWidth) {
tabWidth = tabWidth || 4;
return this.replace(/^\t+/gm, function(tabs) { return ' '.repeat(tabWidth * tabs.length)} );
}