Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to escape code fences #208

Closed
BewhiskeredBard opened this issue Mar 11, 2013 · 14 comments · Fixed by #681
Closed

Unable to escape code fences #208

BewhiskeredBard opened this issue Mar 11, 2013 · 14 comments · Fixed by #681

Comments

@BewhiskeredBard
Copy link

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).

@aprescott
Copy link

Use four leading spaces or leading tabs:

```
my fenced code block
```

Achieved with:

    ```
    my fenced code block
    ```

@BewhiskeredBard
Copy link
Author

Although I am very grateful for the workaround, there's still a bug here.

@mattr-
Copy link
Collaborator

mattr- commented Jun 2, 2013

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.

@notslang
Copy link

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.

@hagenburger
Copy link

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:

  • Way more work (especially when commenting or opening issues on Github)
  • Unable to set a language (showstopper)

@hagenburger
Copy link

Any comments on this? This fix would be a big enhancement for my daily work, especially the documentation of my open-source projects :)

@robin850 robin850 added this to the 3.3.0 milestone Aug 29, 2014
@75lb
Copy link

75lb commented May 4, 2015

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() {}

@jkillian
Copy link

👍 to @hagenburger's suggestion

@solidsnack
Copy link

One cool trick: use Zero Width Space

@ndelangen
Copy link

I'm using your solution @solidsnack, thanks!

@alexindigo
Copy link

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.

@robin850 robin850 removed this from the 3.3.0 milestone Jun 22, 2016
@Henry-E
Copy link

Henry-E commented Jul 25, 2016

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))

bbbrrriiiaaannn added a commit to bbbrrriiiaaannn/aigis that referenced this issue Oct 5, 2016
There's some Markdown weirdness around display nesting '```' code fences. The current README's example with a nested block doesn't terminate correctly for some reason and was including the next section's markdown escaped in it.

Rather than wrapping with number-of-wrapped-backticks+1 this uses [this idea])vmg/redcarpet#208 (comment)) and prefixes the nested instances with zero-width spaces, thanks @solidsnack
@martincizek
Copy link
Contributor

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?

@steinybot
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.