Change tab char expansion from 8 to 4 spaces.

Change tab char expansion from 8 to 4 spaces.

by Luigi Esposito -
Number of replies: 1

I'm using TinyMCE.

Sometimes I type some computer code on a page or in the text of a question (for example, Java code).

To keep the indentation, I switch to the Moodle HTML editor and write my code there, enclosed in a <pre></pre> HTML element.

When I need to type a tab char for indenting, I copy and paste that char from an external text editor.

Alternatively, I can write the code in Notepad++ and then copy and paste it into the Moodle HTML editor.

Well, when I save that page or that question, Moodle does a good job and shows me a perfectly indented Java code.

But I noticed that each tab char was expanded to 8 spaces.

I think it's excessive for me, so I would ask you if I can customize the tab expansion to 4 spaces.

Average of ratings: -
In reply to Luigi Esposito

Re: Change tab char expansion from 8 to 4 spaces.

by Anthony Rimmer -
Hi Luigi, 

You could use the 'tab-size' CSS property? (Though not supported in IE)

It might be worth sticking your code inside a code tag though, so you can target any code directly, and not any other pre-formatted content on your site.

<style>
code {
display:block;
white-space:pre-wrap;
tab-size:2;
-moz-tab-size:2;
}
</style>

<code>
myfunction() {
//my indented code
}
</code>

You can add tabs directly using ALT+0+9 (Windows) or CMD + OPT + TAB (MAC - Untested [From a quick internet search])

Average of ratings: Useful (1)