Indent code with TAB in forum editor

Hi, friends.

Sometimes I post answers on topics here.
And often my answers contain source code samples.
Althrough default reply editor on this forum supports code insertion, it requires each line to be prepended with 4 spaces:

This is the sample

And, because that editor is a basic textarea, you have two options to format source code in your posts properly:

  1. Manually copy and paste 4 spaces in the beginning of each line;
  2. Use external text editor to do that

I’ve tried both of these options and can say they are bad :smiley:

So I made a better solution. It is a short bookmarklet that adds TAB, SHIFT+TAB and auto indenting support into forums editor:


##How to install and use

  1. Copy that code:

javascript:$.getScript(‘https://cdn.jsdelivr.net/taboverride/4.0.2/taboverride.min.js’,function(){var t=$(‘#wmd-input’).css(‘background’, ‘#e5fff0’);tabOverride.tabSize(4);tabOverride.set(t.get(0));});

  1. Add new bookmark in your browser and set that copied code as bookmark URL.

  2. When you have reply editor opened - click and run your bookmark. Textarea should become green, as shown in demo above. After that you can use TAB and SHIFT+TAB.

Based on TabOverride lib by Bill Bryant.

You can also highlight the code in the forum editor and use the </> button to format it (which I find awkward, but other folk like).

Or you can type three backticks on a line above your code, and three on a line below.

```

That’s my preferred method, but it isn’t practical on some European keyboards, which don’t have a backtick key.

Yeah, those two methods suitable when you paste code from external source. But when you write it from scratch right here it becomes a tricky task without possibility to use TAB key.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.