Closed BewhiskeredBard closed 3 years ago
Use four leading spaces or leading tabs:
my fenced code block
Achieved with:
my fenced code block
```
Although I am very grateful for the workaround, there's still a bug here.
I understand your point of view yet humbly disagree that this is a bug.
I think there's an opportunity here to better document how the fenced_code_blocks
option works and that escaping the backticks has no effect and that using the standard markdown four space indent is required if you want to show an example of how to use the fenced_code_blocks
option.
I just ran into this same bug... it would be much nicer if redcarpet let you wrap code blocks that contain sets of 3 backticks by using sets of 4 backticks (like marked supports), just like how you wrap inline code that contains a backtick with 2 backticks on each side, rather than just one.
I’m currently working on documenting the LivingStyleGuide Gem where I have to write a lot of Markdown examples within Markdown which is almost impossibe.
Problem: If you open a code block with ``` it will also be closed by ~~~ and vice versa.
Solution: Only close code blocks with the same 3 characters they have been opened.
@mattr- I agree that this might not be a bug. But I can’t think of any use case where opening and closing code blocks with different characters would make sense. Do you have any?
Example: This should create one big code block:
Look at this Markdown example:
~~~ markdown
Text
code
* List
* List
~~~
Great example, isn’t it?
<p>Look at this Markdown example:</p>
<pre><code class="markdown">Text
</code></pre>
<p>code
```</p>
<ul>
<li>List</li>
<li>List
~~~</li>
</ul>
<p>Great example, isn’t it?</p>
Also @slang800’s idea with the amount of backticks is nice. But I guess checking the character (and using existing syntax) should work in all use cases.
The idea of using the indented code blocks instead of backticks/tildes is:
Any comments on this? This fix would be a big enhancement for my daily work, especially the documentation of my open-source projects :)
In my case, i am trying to write an example of how to use fenced code blocks.. so, my markdown looks something like this (which does not render correctly):
```js
/**
A simple example
@example
```js
var result = one();
*/ function one() {}
if i indent the nested code block, i get this.. it renders but it breaks my example (there is no need to indent a code block, as shown)
/**
A simple example
@example
```js
var result = one();
*/ function one() {}
:+1: to @hagenburger's suggestion
One cool trick: use Zero Width Space
I'm using your solution @solidsnack, thanks!
Yep, for documentation about documentation, readme generators and readme example testing modules, it will be helpful to be a bit more flexible. For example like @slang800 suggested, escaping with more backticks. Thanks.
The easiest way I've found to get the Zero Width Space is from a web browser developer console http://superuser.com/questions/156640/how-can-i-type-u200b-character/1072509#1072509
When using recent versions of Chrome/Chromium, you can use its console to copy the character to clipboard:
copy(String.fromCodePoint(0x200B))
robin850 removed this from the 3.3.0 milestone on 22 Jun 2016
@robin850 I believe I've resolved it, any chance to get it in 3.5.x?
In case anyone is lazy like me, you can copy the zero width space from here https://unicode-table.com/en/200B/. Paste that infront of your code fence and you are good to go.
I need to write an example of markdown with code fencing, so I assumed that adding a backslash before the 3 backticks would work, but it doesn't (compare output with RAW: https://gist.github.com/jordanryanmoore/5136446).