kbjradmin
New Member
- Messages
- 512
- Reaction score
- 2
- Points
- 0
ok, so i wrote a function to find all 'pre' tags with the class name 'code' and strip out the first n number of tabs from each line, then put the new text back in the 'pre' tag.
but for some reason, it's not working. please help.
http://portfolio.kbjrweb.com/web.php?id=1 is an example, the dark box is the 'pre' tag.
Edit:
nevermind, i got it.
for some reason, it wasn't getting through
if ( text[line].substring(0,tabs-1) == "\t".repeat(tabs) )
structure.
anyway, it works now.
Code:
function untabCodePres(tabs)
{
if ( ! tabs ) { var tabs = 5; }
var codeBlocks = document.getElementsByTagName('pre');
for ( var i in codeBlocks )
{
if ( codeBlocks[i].className == 'code' )
{
var text = codeBlocks[i].innerHTML.split("\n");
for ( var line in text )
{
if ( text[line].substring(0,tabs-1) == "\t".repeat(tabs) )
{
text[line] = text[line].substr(tabs);
}
if ( text[line] == '' )
{
delete text[line];
}
}
codeBlocks[i].innerHTML = text.join("\n");
}
}
}
but for some reason, it's not working. please help.
http://portfolio.kbjrweb.com/web.php?id=1 is an example, the dark box is the 'pre' tag.
Edit:
nevermind, i got it.
for some reason, it wasn't getting through
if ( text[line].substring(0,tabs-1) == "\t".repeat(tabs) )
structure.
anyway, it works now.
Last edited: