Home / GitHub Page

Code Block Syntax Highlighting - Text

I have been using ```text to create code blocks that have no syntax highlighting. I am now using Joplin 1.0.142 (Win10 x64) and have noticed that ```text now applies some kind of syntax highlighting. For instance it picks out odd words like “service” and highlights them orange. I also noticed that in blocks that contain a list of URLs “https://” is intially highlighted blue with the remainder of the url green and then after a few entries the whole url including https is green. Shouldn’t the text code block be without syntax highlighting?

That’s a good point. I’ve also noticed several issues with syntax highlighting.

But to answer your question: yes, a text code block should be without highlighting.

Should I file this? It’s a really REALLY annoying bug.

For some stuff I used ````tex` which worked for me, but since that usually refers to LaTeX documents… I am sure the fact that I got it to work for me was just dumb luck.

Anyway. “text” should be the right qualifier. Yet, it doesn’t render correctly.

Unfortunately text does not work. After some research I found out that one has to use plaintext instead. :frowning:

This is not really a bug actually. There are two types of blocks in Joplin:

  • Fenced code blocks, that start with ``` and that are meant to contain syntax highlighted code. If that’s code you have, you should use this.
  • Preformatted text blocks, which are indented with four spaces or a tab, and are meant to display preformatted text (same as HTML PRE tag).

The problem is when you used fenced code block when all you want is preformatted text. In that case it will try to auto-detect code, and will obviously wrongly guess since it’s not code inside.

Perhaps we could indeed add a qualifier to fenced code block that would make it behave like preformatted text block. Is “text” a standard? What does StackExchange use for example?

1 Like

highlightjs uses plaintext. Maybe someone can open a feature request with them to make text an alias of plaintext

1 Like

I was trying to find out how to do a code-block in a note and saw this post about using a triple tick to begin plain text code block. It seems to be working for me, but the other posts indicate there is still a problem. I am using version 1.0.167. Has this be resolved? Can I start any code-block with and end it with `
I don’t need highlighting in the code, I just want the code-block to be plain text.
Thanks.

Joplin doesn’t seem to have a problem that needs resolving and it works fine for me.

This is a simplified summary…

There is inline code which is where you surround a word or words within a line of text with a single backtick so `my phrase` gives my phrase.

You can achieve the same for a line by indenting the line with four spaces or a tab so:

    my phrase

Shows as

my phrase

Neither of these has any kind of code highlighting. They are just pre-formatted text blocks.

There are also code blocks where you start with three backticks and end with three backticks, with the backticks being on their own line. This is a “fenced code block”. This enables you to mark swathes of text as code. This code block however can have code highlighting to make the code easier to read

Of course unless you specify what type of code you have “fenced” the interpreter can only guess so you can tell it by adding a keyword after the first set of three backticks.

For instance

```plaintext

will tell the interpreter that everything that follows up to the closing set of backticks is plain text. (The interpreter Joplin uses appears to use plaintext whereas others, such as this forum, use text.)

```bash

will tell the interpreter that everything that follows up to the closing set of backticks is a bash script and it will highlight the code as such.

So, in Joplin

```plaintext
#!/bin/bash
# declare STRING variable
STRING="Hello World"
#print variable on a screen
echo $STRING
```

Shows as

#!/bin/bash
# declare STRING variable
STRING="Hello World"
#print variable on a screen
echo $STRING

But

```bash
#!/bin/bash
# declare STRING variable
STRING="Hello World"
#print variable on a screen
echo $STRING
```

Shows as

#!/bin/bash
# declare STRING variable
STRING="Hello World"
#print variable on a screen
echo $STRING

(the colours may vary in Joplin to what you see above but it will basically do the the same thing)

Other keywords I have seen mentioned on the web include,

apache
bash
coffeescript
cpp
cs
css
diff
go
html
http
ini
java
javascript
json
makefile
markdown
nginx
objectivec
perl
php
plaintext
python
ruby
shell
sql
xml

I have not tried them all so I cannot say if the interpreter Joplin uses understands all of them. Just try it and see!

Of course if you just want to ensure all your fenced blocks are plain text just put plaintext after the first three backticks and you are done.

1 Like