Using Highlight.js
• Download Highlight
Highlight is a specially built for markdown, code highlighting and 26 code styles that support 54 programming languages. Go to the download page and select the language you are using, then click the Download button to download it, and then unzip it and copy the code style files you like in the Highlight.pack.js and style directories to your project.
• Use Highlight
It is usually referenced once on the layout page, for example:
The code is as follows |
Copy Code |
<link rel= "stylesheet" href= "/css/tomorrow-night.css" type= "text/css" media= "screen, projection"/> <script src= "/js/highlight.pack.js" type= "Text/javascript" ></script> <script>hljs.inithighlightingonload ();</script> |
Note the path of the reference
• code block notation
Specifies the language of the code, in the form of:
The code is as follows |
Copy Code |
"' PHP $a = ' a '; echo $a; ```
|
But previously used rdiscount this interpreter to parse the above code incorrectly, so use the following redcarpet.
Using Redcarpet
• Install Redcarpet
The code is as follows |
Copy Code |
Lch@localhost:luchanghong.github.com $ sudo gem install Redcarpet Password: Fetching:redcarpet-2.2.2.gem (100%) Building native extensions. This is could take a while ... Successfully installed redcarpet-2.2.2 1 Gem installed Installing RI documentation for redcarpet-2.2.2 ... Installing RDOC documentation for redcarpet-2.2.2 ... |
• Modify _config.yml
code is as follows |
copy code |
Markdown: Redcarpet Redcarpet: Extensions: ["No_intra_emphasis", "Fenced_code_blocks", "Autolink", "Tables", " With_toc_data "] |