GitHub-flavored markdown supports syntax highlighting in codeblocks. This is done by adding the name of the language next to the triple-grave codeblock markers:
```ruby require 'redcarpet' markdown = Redcarpet.new("Hello World!") puts markdown.to_html ```
Standard markdown also supports inline codeblocks by wrapping text in `single graves`
. Is there any way to add syntax highlighting to these inline codeblocks?
To highlight code, write the name of the language the code is written in after the initial triple backticks. In the above example, the code is written in JavaScript, and hence javascript is added after triple backticks.
To link to multiple lines of highlighted code, select your first line of code and then CTRL+SHIFT click on the last line of code you want to highlight. Notice the URL is now appended with a range of line numbers (e.g. https://github.com/…/functions.php#L117-L148).
Just use the HTML <u> tag (recommended) or the <ins> tag inside your markdown for this. The HTML tag <ins> is the HTML "insert tag", and is usually displayed as underlined.
To format a code block in Markdown, indent every line of the block by at least four spaces. An indented code block cannot interrupt a paragraph, so you must insert at least one blank line between a paragraph the indented code block that follows.
GitHub comments, wikis, README.md etc. use GFM, essentially CommonMark with some extensions. There it's not possible.
However, GitHub Pages uses Jekyll and by extension kramdown where you can use:
`x = 4`{:.ruby}
P.S. If you happen to use pandoc, the syntax is:
`x = 4`{.ruby}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With