Jhun Jhun - 1 month ago 6
HTML Question

auto tab in C to HTML

how can I convert auto tabs in C code to html, so it will look neat in html to look aligned. Is it safe just to use 4spaces? but some times, 1tab is not 4 spaces, 1,2, or 3 space only. Pls help, thanks!

int x ; /* comment tab */
x = 0U ; /* comment tab */

if ( Gvar == 3U) /* comment tab */
{ /* comment tab */
x++ ; /* comment tab */
} /* comment tab */
Gvar = 99U ; /* comment tab */

return ( 0 ) /* comment tab */

Answer

Well obviously you can't just blithely convert every tab into four spaces. That's not how tabs work. Instead you want each tab character to advance the output position to the next tab stop.

You have basically two options:

1. Specify a CSS tab-size:

pre { tab-size: 4; -o-tab-size: 4; -moz-tab-size: 4; }
<pre>
int main() {
	return 0;		/* This is a comment */
}
</pre>

This is the simplest solution, but unfortunately the tab-size rule isn't recognized by IE or Edge.

2. Pre-process the source code:

Pipe the C source code through the expand command line utility to convert all the tabs into spaces. For example:

expand -t4 <c_source.c >c_source_with_expanded_tabs.c