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

Already on GitHub? Sign in to your account

octopress-like behavior of backticks #187

Closed
LeonB opened this Issue Jan 7, 2013 · 3 comments

Comments

Projects
None yet
4 participants

LeonB commented Jan 7, 2013

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?

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.

Collaborator

robin850 commented Jun 23, 2013

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! ❤️

@robin850 robin850 closed this Jun 23, 2013

@robin850 robin850 referenced this issue in jekyll/jekyll Dec 29, 2013

Closed

The linenos support while using ``` #1887

Contributor

chitsaou commented Jan 16, 2015

Hi there, I have created an HTML::Pipeline filter to do this. If you are using Jekyll you can use it painlessly. See https://github.com/chitsaou/markdown-highlight-extended-filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment