Class: WCC::Contentful::App::MarkdownRenderer
- Inherits:
- 
      Object
      
        - Object
- WCC::Contentful::App::MarkdownRenderer
 
- Defined in:
- lib/wcc/contentful/app/markdown_renderer.rb
Instance Attribute Summary collapse
- 
  
    
      #extensions  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute extensions. 
- 
  
    
      #options  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute options. 
Instance Method Summary collapse
- 
  
    
      #initialize(options = nil)  ⇒ MarkdownRenderer 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of MarkdownRenderer. 
- #markdown(text) ⇒ Object (also: #call)
Constructor Details
#initialize(options = nil) ⇒ MarkdownRenderer
Returns a new instance of MarkdownRenderer.
| 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # File 'lib/wcc/contentful/app/markdown_renderer.rb', line 8 def initialize( = nil) @extensions = { autolink: true, superscript: true, disable_indented_code_blocks: true, tables: true }.merge!(&.delete(:extensions) || {}) @options = { filter_html: true, hard_wrap: true, link_attributes: { target: '_blank' }, space_after_headers: true, fenced_code_blocks: true }.merge!( || {}) end | 
Instance Attribute Details
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
| 6 7 8 | # File 'lib/wcc/contentful/app/markdown_renderer.rb', line 6 def extensions @extensions end | 
#options ⇒ Object (readonly)
Returns the value of attribute options.
| 6 7 8 | # File 'lib/wcc/contentful/app/markdown_renderer.rb', line 6 def @options end | 
Instance Method Details
#markdown(text) ⇒ Object Also known as: call
| 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # File 'lib/wcc/contentful/app/markdown_renderer.rb', line 25 def markdown(text) raise ArgumentError, 'markdown method requires text' unless text markdown_links = links_within_markdown(text) links_with_classes, raw_classes = gather_links_with_classes_data(markdown_links) = @options.merge({ links_with_classes: links_with_classes }) renderer = ::WCC::Contentful::App::CustomMarkdownRender.new() markdown = ::Redcarpet::Markdown.new(renderer, extensions) markdown.render(remove_markdown_href_class_syntax(raw_classes, text)) end |