Unable to escape code fences #208

Open
jordanryanmoore opened this Issue Mar 11, 2013 · 12 comments

Comments

Projects
None yet
@jordanryanmoore

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

This comment has been minimized.

Show comment Hide comment
@aprescott

aprescott Mar 11, 2013

Use four leading spaces or leading tabs:

```
my fenced code block
```

Achieved with:

    ```
    my fenced code block
    ```

Use four leading spaces or leading tabs:

```
my fenced code block
```

Achieved with:

    ```
    my fenced code block
    ```
@jordanryanmoore

This comment has been minimized.

Show comment Hide comment
@jordanryanmoore

jordanryanmoore Mar 13, 2013

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

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

@mattr-

This comment has been minimized.

Show comment Hide comment
@mattr-

mattr- Jun 2, 2013

Collaborator

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.

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.

@slang800

This comment has been minimized.

Show comment Hide comment
@slang800

slang800 Aug 12, 2014

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

This comment has been minimized.

Show comment Hide comment
@hagenburger

hagenburger Aug 14, 2014

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)

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

This comment has been minimized.

Show comment Hide comment
@hagenburger

hagenburger Aug 29, 2014

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

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

This comment has been minimized.

Show comment Hide comment
@75lb

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

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

This comment has been minimized.

Show comment Hide comment
@JKillian

JKillian Sep 30, 2015

👍 to @hagenburger's suggestion

👍 to @hagenburger's suggestion

@solidsnack

This comment has been minimized.

Show comment Hide comment
@solidsnack

solidsnack Dec 12, 2015

One cool trick: use Zero Width Space

One cool trick: use Zero Width Space

@ndelangen

This comment has been minimized.

Show comment Hide comment
@ndelangen

ndelangen Jan 15, 2016

I'm using your solution @solidsnack, thanks!

I'm using your solution @solidsnack, thanks!

@alexindigo

This comment has been minimized.

Show comment Hide comment
@alexindigo

alexindigo Jan 30, 2016

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.

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

This comment has been minimized.

Show comment Hide comment
@Henry-E

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

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

BrianCS added a commit to BrianCS/aigis that referenced this issue Oct 5, 2016

Prefix nested code-fence with 0-width space
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment