Class: ApplicationMarkdown

Inherits:
MarkdownRails::Renderer::Rails show all
Includes:
Redcarpet::Render::SmartyPants
Defined in:
lib/generators/markdown_rails/install/templates/app/markdown/application_markdown.rb

Overview

You should read the docs at github.com/vmg/redcarpet and probably delete a bunch of stuff below if you don’t need it.

Instance Method Summary collapse

Methods inherited from MarkdownRails::Renderer::Base

#renderer

Instance Method Details

#block_code(code, language) ⇒ Object

These methods are called as the Markdown document is parsed. Block-level calls are documented at github.com/vmg/redcarpet#block-level-calls and span level calls are documented at github.com/vmg/redcarpet#block-level-calls so feel free to add more as you see fit.



35
36
37
38
39
# File 'lib/generators/markdown_rails/install/templates/app/markdown/application_markdown.rb', line 35

def block_code(code, language)
   :pre, class: language do
    code # You could implement syntax highlighting here with Rouge.
  end
end

#enableObject

These flags control features in the Redcarpet renderer, which you can read about at github.com/vmg/redcarpet#and-its-like-really-simple-to-use Make sure you know what you’re doing if you’re using this to render user inputs.



27
28
29
# File 'lib/generators/markdown_rails/install/templates/app/markdown/application_markdown.rb', line 27

def enable
  [:fenced_code_blocks]
end

#image(link, title, alt) ⇒ Object

Example of how you might override the images to show embeds, like a YouTube video.



42
43
44
45
46
47
48
49
50
# File 'lib/generators/markdown_rails/install/templates/app/markdown/application_markdown.rb', line 42

def image(link, title, alt)
  url = URI(link)
  case url.host
  when "www.youtube.com"
    youtube_tag url, alt
  else
    super
  end
end