BVB Source Codes

hologram Show markdown_renderer.rb Source code

Return Download hologram: download markdown_renderer.rb Source code - Download hologram Source code - Type:.rb
  1. require 'hologram/block_code_renderer'
  2.  
  3. include ERB::Util
  4.  
  5. module Hologram
  6.   class MarkdownRenderer < Redcarpet::Render::HTML
  7.     def initialize(opts={})
  8.       super(opts)
  9.       @link_helper = opts[:link_helper]
  10.     end
  11.  
  12.     def list(contents, list_type)
  13.       case list_type
  14.       when :ordered
  15.         "<ol class=\"#{css_class_name}\">#{contents}</ol>"
  16.       else
  17.         "<ul class=\"#{css_class_name}\">#{contents}</ul>"
  18.       end
  19.     end
  20.  
  21.     def paragraph(text)
  22.       "<p class=\"#{css_class_name}\">#{text}</p>"
  23.     end
  24.  
  25.     def table(header, body)
  26.       "<table class=\"#{css_class_name}\"> #{header} #{body} </table>"
  27.     end
  28.  
  29.     def codespan(code)
  30.       "<code class=\"#{css_class_name}\">#{html_escape(code)}</code>"
  31.     end
  32.  
  33.     def link(link, title, content)
  34.       "<a class=\"#{css_class_name}\" href=\"#{link}\" title=\"#{title || link}\">#{content}</a>"
  35.     end
  36.  
  37.     def block_code(code, language)
  38.       BlockCodeRenderer.new(code, language).render
  39.     end
  40.  
  41.     def preprocess(full_document)
  42.       if link_helper
  43.         link_defs + "\n" + full_document
  44.       else
  45.         full_document
  46.       end
  47.     end
  48.  
  49.     def postprocess(full_document)
  50.       invalid_links = full_document.scan(/(?: \[ [\s\w]+ \]){2}/x)
  51.  
  52.       invalid_links.each do |invalid_link|
  53.         component = /\[.+\]/.match(invalid_link)[1]
  54.         DisplayMessage.warning("Invalid reference link - #{invalid_link}." +
  55.                                "Presumably the component #{component} does not exist.")
  56.       end
  57.  
  58.       full_document
  59.     end
  60.  
  61.     def css_class_name
  62.       'styleguide'
  63.     end
  64.  
  65.     private
  66.  
  67.     attr_reader :link_helper
  68.  
  69.     def link_defs
  70.       @_link_defs ||= link_helper.all_links.map { |c_name, link| "[#{c_name}]: #{link}" }.join("\n")
  71.     end
  72.   end
  73. end
  74.  
downloadmarkdown_renderer.rb Source code - Download hologram Source code
Related Source Codes/Software:
www.html5rocks.com - ....a top-notch resource for web developer 2017-05-12
MTStatusBarOverlay - A custom iOS status bar overlay seen in Apps like ... 2017-05-12
blueprint - Reverse engineer server configuration ... 2017-05-12
PullToRefresh - A simple iPhone TableViewController for adding the... 2017-05-12
mrjob - Run MapReduce jobs on Hadoop or Amazon Web Service... 2017-05-11
isso - a Disqus alternative https:... 2017-05-12
python3-cookbook - "The Python Cookbook" 3 rd Edition Translatio 2017-05-12
TSA-Travel-Sentry-master-keys - 3D reproduction of TSA Master key 2017-05-12
fatfree - A powerful yet easy-to-use PHP micro-framework des... 2017-05-13
rolify - Role management library with the resource scoping 2017-05-13
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top