Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/naoty/redcarpet_filename_extension

Redcarpet custom renderer for code blocks with filename.
https://github.com/naoty/redcarpet_filename_extension

Last synced: about 1 month ago
JSON representation

Redcarpet custom renderer for code blocks with filename.

Awesome Lists containing this project

README

        

# Redcarpet filename extension

Redcarpet custom renderer for code blocks with filename.

## Usage

```rb
renderer = BlockCodeWithFilename.new
markdown = Redcarpet::Markdown.new(renderer, fenced_code_blocks: true)
markdown.render(markdown_content)
```

When you add filename after language in your fenced code block, this custom renderer will recognize the filename.

## Example

```markdown
```rb:greeter.rb
class Greeter
def initialize(name)
@name = name.capitalize
end

def salute
puts "Hello #{@name}!"
end
end

# Create a new object
g = Greeter.new("world")

# Output "Hello World!"
g.salute
\```
```

This fenced block code is rendered like this.

![screenshot](screenshot.png "screenshot")