Highlight.js: Tabs width

Created on 15 Jul 2014  Â·  7Comments  Â·  Source: highlightjs/highlight.js

I am happy using TABs, so I do not want to replace a TAB with spaces, but what I would like to is to change the TAB width, Currently a TAB is around 8 spaces. I would like to have a TAB which is 4 spaces.

Any way I can achieve this?

Most helpful comment

Strange, the configure worked for me but I'm using hljs.highlightBlock directly instead of initHighlighting, not sure if it makes a difference.

Alternatively, there is a CSS3 attribute for this now: http://www.w3schools.com/cssref/css3_pr_tab-size.asp

All 7 comments

When you say that you don't want to replace tabs with spaces, do you mean you don't do it manually or you don't want spaces in the browser?

If the former then this option will take care of it:

hljs.configure({tabReplace: '    '})

If the latter then your can't do anything about it as browsers display tabs however they like, it can't be styled.

Ok, didn't know that the tab width is set globally by the browser and can't be changed on a DOM node basis.
will stick to tabReplace then.

Thank you.

Just tried this -- what I'm finding is that the tabs in my top-of-function comments aren't replaced and thus still show up in the browser width width 8.

My tabs aren't getting replaced either. Here's my initialization.

$(document).ready(function () {
    hljs.configure({tabReplace: '    '});
    hljs.initHighlighting();
});

FYI, I got around this by converting tabs to spaces on the server and not
having Highlight.js do the conversion.

Remember that this conversion is actually quite tricky, because in code
comments where this is non-whitespace to the left of the tabs, the number
of spaces that a tab should be replaced with depends on what is to the left.

On Fri, Dec 9, 2016 at 12:51 PM, Luke Hatfield notifications@github.com
wrote:

My tabs aren't getting replaced either. Here's my initialization.

$(document).ready(function () {
hljs.configure({tabReplace: ' '});
hljs.initHighlighting();
});

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/isagalaev/highlight.js/issues/508#issuecomment-266077036,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABztWv2Je4rO0g7EkudFfqewJCEmsSgqks5rGZUcgaJpZM4CNHJE
.

Strange, the configure worked for me but I'm using hljs.highlightBlock directly instead of initHighlighting, not sure if it makes a difference.

Alternatively, there is a CSS3 attribute for this now: http://www.w3schools.com/cssref/css3_pr_tab-size.asp

Thanks all. Love the CSS3 fix. That'll keep me going for now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gskinner picture gskinner  Â·  4Comments

zhouxy666 picture zhouxy666  Â·  3Comments

sustained picture sustained  Â·  4Comments

Lestoroer picture Lestoroer  Â·  7Comments

vladshcherbin picture vladshcherbin  Â·  5Comments