'pre' or 'text' code blocks use keyword highlighting


(Clay Heaton) #1

I have two Discourse installs - one for testing and the other in production. They are running the same version: 1.1.0.beta5.

For some reason, the pre or text code blocks still display with keyword highlighting on the ‘production’ instance of Discourse. In other words:

```pre
name, group, ranking
```

looks like this:

name, group, ranking

instead of this:

name, group, ranking

Any idea why that would be or suggestions for debugging it?


(Clay Heaton) #2

I just upgraded it to 1.1.0.beta6b and rebuilt the app – no dice… the pre code block highlighting still doesn’t work properly.


(Régis Hanol) #3

Not sure I understand the problem but have you changed the default code lang site setting?


(Clay Heaton) #4

I think this is a bug, actually. I realized that I had the “autohighlight all code” setting checked, which specifies

Force apply code highlighting to all preformatted code blocks even when they didn’t explicitly specify the language.

However, if I specify pre or text as the “language,” that means that I don’t want any code highlighting at all. I think that the setting should respect the pre and text “code types” when they are explicitly entered and not apply formatting in those instances.

With that selected, I would expect that:

```
name, group, ranking
```

would result in

name, group, ranking

but that

```pre
name, group, ranking
```

would result in

name, group, ranking

Notice the difference in the syntax highlighting (group is bold).


(Jeff Atwood) #5

Unrelated, that setting has to do with four space indent. Which you should be using here anyway IMO.


(Sam Saffron) #6

I am kind of against this “autohighlight all code” setting, @codinghorror can I remove?


(Jeff Atwood) #7

Probably fine to remove. But again, if you do not want highlighting, you should be using ctrl+k and 4 space indent.


(Clay Heaton) #8

Agreed. I stumbled across this with a larger block of code and just reduced it to one line for the example here.


(Sam Saffron) #9

I use ```text quite a lot, I prefer it to indenting, I find the indenting harder to read and control.


(Jeff Atwood) #10

Sure, but don’t expect that hack to work anywhere else Markdown is supported – it’s teaching people bad habits, which I just can’t get behind.

Do you use triple-backtick to indent code in your editor? Nope, you select a code block and press the indent key. Try it here:

  1. select a block of text.
  2. press ctrl+k
  3. done

I find it hard to believe you don’t do literally that in your editor, on a daily basis, dozens of times. Indent and undent is a basic core programmer editor function.

I am fine with triple backtick for actual code that needs to be syntax highlighted and have other special “code” behaviors, but this is not code, it’s preformatted text… which should be indented 4 spaces.


(Sam Saffron) #11

There are quite a few use cases where I find backticks more useful.

For example when pasting a long log snippet. If I type, ```text and then paste the snippet and type ``` I find it easier than fighting to select the big piece of text.

The spec for three backticks and 4 spaces is the same, both generate PRE CODE, only difference is that we add hinting with a special class on the CODE (lang-auto hljs). All the hinting is custom and really should be in the spec, clearly without the hljs stuff.


(Dave McClure) #12

Hi, I’m Dave, and I too am a BackTicker.

I started BackTicking on Trello cards in early 2013 and I haven’t stopped since. These days, I BackTick on GitHub, BitBucket and Discourse too… To be honest, I didn’t even know there was another way to live until very recently, but I just can’t stop. Its… too easy not to.

No, but you generally use some special characters to indicate not-code in your code editor… # or // or /* */

So, using characters to indicate going between code and not-code is well established habit too.

It may be wrong but it feels so right.

:smile: