Skip to content
This repository

octopress-like behavior of backticks #187

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

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:

def foo() end

This gives you output for use with syntax highlighting:

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

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

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

That would let you do

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

and handle the extra metadata.

Robin Dupret

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.