Class: Jazzy::JazzyHTML
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- Jazzy::JazzyHTML
- Includes:
- Redcarpet::Render::SmartyPants, Rouge::Plugins::Redcarpet
- Defined in:
- lib/jazzy/jazzy_markdown.rb
Constant Summary collapse
- SPECIAL_LIST_TYPES =
%w(Attention Author Authors Bug Complexity Copyright Date Experiment Important Invariant Note Parameter Postcondition Precondition Remark Requires Returns See SeeAlso Since TODO Throws Version Warning).freeze
- SPECIAL_LIST_TYPE_REGEX =
%r{ \A\s* # optional leading spaces (<p>\s*)? # optional opening p tag # any one of our special list types (#{SPECIAL_LIST_TYPES.map(&Regexp.method(:escape)).join('|')}) [\s:] # followed by either a space or a colon }ix
- ELIDED_LI_TOKEN =
'7wNVzLB0OYPL2eGlPKu8q4vITltqh0Y6DPZf659TPMAeYh49o'.freeze
- OPTIONS =
{ autolink: true, fenced_code_blocks: true, no_intra_emphasis: true, quote: true, strikethrough: true, space_after_headers: false, tables: true, }.freeze
Instance Method Summary collapse
- #header(text, header_level) ⇒ Object
- #list(text, list_type) ⇒ Object
- #list_item(text, _list_type) ⇒ Object
- #render_aside(type, text) ⇒ Object
Instance Method Details
#header(text, header_level) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/jazzy/jazzy_markdown.rb', line 10 def header(text, header_level) text_slug = text.gsub(/[^\w]+/, '-') .downcase .sub(/^-/, '') .sub(/-$/, '') "<a href='##{text_slug}' class='anchor' aria-hidden=true>" \ '<span class="header-anchor"></span>' \ '</a>' \ "<h#{header_level} id='#{text_slug}'>#{text}</h#{header_level}>\n" end |
#list(text, list_type) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/jazzy/jazzy_markdown.rb', line 77 def list(text, list_type) elided = text.gsub!(ELIDED_LI_TOKEN, '') return if text =~ /\A\s*\Z/ && elided return text if text =~ /class="aside-title"/ str = "\n" str << (list_type == :ordered ? "<ol>\n" : "<ul>\n") str << text str << (list_type == :ordered ? "</ol>\n" : "</ul>\n") end |
#list_item(text, _list_type) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/jazzy/jazzy_markdown.rb', line 57 def list_item(text, _list_type) if text =~ SPECIAL_LIST_TYPE_REGEX type = Regexp.last_match(2) return ELIDED_LI_TOKEN if type =~ /parameter|returns/ return render_aside(type, text.sub(/#{Regexp.escape(type)}:\s+/, '')) end str = '<li>' str << text.strip str << "</li>\n" end |
#render_aside(type, text) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/jazzy/jazzy_markdown.rb', line 68 def render_aside(type, text) <<-HTML <div class="aside aside-#{type.underscore.tr('_', '-')}"> <p class="aside-title">#{type.underscore.humanize}</p> #{text} </div> HTML end |