expressive-code icon indicating copy to clipboard operation
expressive-code copied to clipboard

`tabWidth` ignored on imported code

Open mrchantey opened this issue 1 year ago • 2 comments

I'm working with the Starlight Basics template and it seems the tabWidth setting is working correctly with inline code blocks but being ignored for imported files in the <Code> component. Is there a setting i've missed?

Stackblitz here

Screenshot 2024-06-13 111602

Screenshot 2024-06-13 111741

mrchantey avatar Jun 13 '24 01:06 mrchantey

Hello! Thank you for reporting this! I just had a look at the code and you're right, the tabWidth setting is only used by the rehype plugin to convert tabs in Markdown/MDX source code to spaces. The Code component uses another code path which doesn't get processed by this setting at all.

I think I can fix this by not replacing the tabs with spaces at all, but using CSS instead to apply the desired tab width to the rendered code blocks. Is my assumption correct that you primarily care about the displayed width of the leading indentation and don't mind whether the HTML output contains spaces or actual tabs?

hippotastic avatar Jun 15 '24 09:06 hippotastic

Yes thats right, any way of being able to adjust the displayed width would be awesome.

mrchantey avatar Jun 16 '24 04:06 mrchantey

I made the replacement of tabs with spaces consistent between fenced code blocks and the <Code> component in version 0.38.2, published to NPM today.

Thanks again for reporting this and sorry it took so long!

hippotastic avatar Nov 05 '24 20:11 hippotastic