Skip to content
This repository

octopress-like behavior of backticks #187

Closed
LeonB opened this Issue January 06, 2013 · 2 comments

3 participants

Leon Bogaert Robin Dupret Adam Prescott
Leon Bogaert

I really like the fenced code block thingy of Octopress:

     ``` ruby Example code
    do_somethin()
    ```

Which generates a figure & figcaption element.

Is this a feature that could be added to redcarpet? If not, would it be possible to extend redcarpet myself to add this behavior?

Adam Prescott

Redcarpet does support triple-backtick fenced codeblocks with the :fenced_code_blocks option, although it only allows a single word:

```ruby
def foo() end
```

This gives you output for use with syntax highlighting:

<pre><code class="ruby">def foo() end
</code></pre>

However, if you use multiple words with Redcarpet,

```ruby Example code
def foo() end
```

then you get this instead:

So perhaps you could write your own Redcarpet renderer that accepts a special character for the first line of a code block and then does what you want?

class Foo < Redcarpet::Render::SmartyHTML
  SPECIAL_CHARACTER = "&"

  def block_code(code, language)
    if code[0] == #{SPECIAL_CHARACTER}/
      # ...
    else
      # ...
    end
  end
end

That would let you do

```&ruby Example code ...
def foo() end
```

and handle the extra metadata.

Robin Dupret
Collaborator

I'm closing this since this feature it's not part of the specs and it can eventually be implemented via a custom render object. Thanks for your contribution to Redcarpet everyone! :heart:

Robin Dupret robin850 closed this June 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.