Format MySQL code in Markdown/Macdown editors

I have tried to apply [four] spaces with ~~~sql markup before the ... code snippet

In Brief:

  • Don't mix indentation and code fencing
  • Check the options in your markdown processor
  • Make sure you use enough tilde characters, ~~~ is not enough, ~~~~ is.

Longer answer:

1. Don't mix indentation and code-fencing

You must choose between indented code blocks and fenced code blocks. Partial mixtures of alternative syntaxes won't work.

# Code Block #

What follows is a fenced code block. 
Note that all text starts immediately in the left margin. 
There is no indentation of the fences. 
There are no extra space characters at the start of these lines.

~~~~sql
update employee
  set salary = salary * 2
  where salary < 100000
~~~~

The following will not work

    ~~~~sql
    update employee
      set salary = salary * 2
      where salary < 100000
    ~~~~

You cannot mix indentation and fencing.

The syntax identifiers are part of the fenced code block syntax. You must also end the code block with a line of tildes.

SQL is a supported language for syntax highlighting.

2. Macdown options

You must also "tick the Enable highlighting in code blocks option." in Macdown.

Image of Macdown Preferences dialogue

3. Number of tilde (~) characters is important

(Note O.P. Ugol eventually noticed this - see comments. Initially we both overlooked it)

~~~sql has too few tilde characters, only three

~~~~sql has the correct number of tilde characters to indicate a "fenced block"