Reputation: 63
I was trying to write some markdown code using markdown in github, but it always leads to some strange format, is there any idea about this issue?
For example: I wanna
# header1 #
but it always display as real header
and it also happens to code block, i wanna
```ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
```
but I got
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
that is so confusing. Is there a good way to write it in markdown?
Upvotes: 2
Views: 381
Reputation: 2599
You can use backslash to escape Markdown syntax. Just put it in the beginning of the line. Just try Markdown editor online and you will simply see how it works.
Upvotes: 0
Reputation: 1323115
Another tip is simply to wrap your markdown code in <pre></pre>
(that avoids the need to add 4 spaces at the beginning of each line)
# tilte ```` ruby code ````
Upvotes: 2
Reputation: 84343
You can escape characters like # or _ in Markdown with a backslash. For example:
\# header 1
If you look at the source code of this post, you'll actually notice that I had to escape the escape character so that the backslash would display in the answer, but a single backslash is all you need to have a special character rendered literally.
You can also use pre-formatted code blocks by indenting your text 4 spaces. For example:
# header 1
Again,if you look at the source you'll see I actually indented 8 spaces so that the code block shows 4 space characters. However, indenting by 4 spaces is generally all you need to display your Markdown source, unless you're trying to be very meta with your rendering.
Upvotes: 3