Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format MySQL code in Markdown/Macdown editors

I'm trying to find out which is the smartest way for render some pieces of MySQL queries with Markdown/Macdown editors.

I have tried to apply 4 spaces with ˜˜˜sql markup before the query code snippet but it seems not working well because it doesn't show code highlights.

See the screenshot below:

enter image description here

Any suggestions? Thanks in advice.

like image 812
UgoL Avatar asked May 22 '17 08:05

UgoL


1 Answers

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"

like image 179
RedGrittyBrick Avatar answered Nov 10 '22 14:11

RedGrittyBrick