Class: Jazzy::Markdown::JazzyHTML
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- Jazzy::Markdown::JazzyHTML
- Includes:
- Redcarpet::Render::SmartyPants, Rouge::Plugins::Redcarpet
- Defined in:
- lib/jazzy/jazzy_markdown.rb
Direct Known Subclasses
Constant Summary collapse
- UNIQUELY_HANDLED_CALLOUTS =
%w[parameters parameter returns].freeze
- GENERAL_CALLOUTS =
%w[attention author authors bug complexity copyright date experiment important invariant keyword mutatingvariant nonmutatingvariant note postcondition precondition recommended recommendedover remark remarks requires see seealso since todo throws version warning].freeze
- SPECIAL_LIST_TYPES =
(UNIQUELY_HANDLED_CALLOUTS + GENERAL_CALLOUTS).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
Instance Attribute Summary collapse
-
#default_language ⇒ Object
Returns the value of attribute default_language.
Instance Method Summary collapse
- #block_code(code, language) ⇒ Object
- #codespan(text) ⇒ Object
- #header(text, header_level) ⇒ Object
- #list(text, list_type) ⇒ Object
- #list_item(text, _list_type) ⇒ Object
- #render_aside(type, text) ⇒ Object
- #rouge_formatter(lexer) ⇒ Object
Instance Attribute Details
#default_language ⇒ Object
Returns the value of attribute default_language.
14 15 16 |
# File 'lib/jazzy/jazzy_markdown.rb', line 14 def default_language @default_language end |
Instance Method Details
#block_code(code, language) ⇒ Object
119 120 121 |
# File 'lib/jazzy/jazzy_markdown.rb', line 119 def block_code(code, language) super(code, language || default_language) end |
#codespan(text) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jazzy/jazzy_markdown.rb', line 27 def codespan(text) if /^\$\$(.*)\$\$$/m =~ text o = ["<div class='math m-block'>", Regexp.last_match[1], '</div>'] Markdown.has_math = true elsif /^\$(.*)\$$/m =~ text o = ["<span class='math m-inline'>", Regexp.last_match[1], '</span>'] Markdown.has_math = true else o = ['<code>', text, '</code>'] end o[0] + CGI.escapeHTML(o[1]) + o[2] end |
#header(text, header_level) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/jazzy/jazzy_markdown.rb', line 16 def header(text, header_level) text_slug = text.gsub(/[^[[:word:]]]+/, '-') .downcase .sub(/^-/, '') .sub(/-$/, '') "<h#{header_level} id='#{text_slug}' class='heading'>" \ "#{text}" \ "</h#{header_level}>\n" end |
#list(text, list_type) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/jazzy/jazzy_markdown.rb', line 109 def list(text, list_type) elided = text.gsub!(ELIDED_LI_TOKEN, '') return if text =~ /\A\s*\Z/ && elided str = "\n" str << (list_type == :ordered ? "<ol>\n" : "<ul>\n") str << text str << (list_type == :ordered ? "</ol>\n" : "</ul>\n") str.gsub(%r{\n?<ul>\n<\/ul>}, '') end |
#list_item(text, _list_type) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/jazzy/jazzy_markdown.rb', line 87 def list_item(text, _list_type) if text =~ SPECIAL_LIST_TYPE_REGEX type = Regexp.last_match(2) if UNIQUELY_HANDLED_CALLOUTS.include? type.downcase return ELIDED_LI_TOKEN end 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
100 101 102 103 104 105 106 107 |
# File 'lib/jazzy/jazzy_markdown.rb', line 100 def render_aside(type, text) <<-HTML </ul><div class="aside aside-#{type.underscore.tr('_', '-')}"> <p class="aside-title">#{type.underscore.humanize}</p> #{text} </div><ul> HTML end |
#rouge_formatter(lexer) ⇒ Object
123 124 125 |
# File 'lib/jazzy/jazzy_markdown.rb', line 123 def rouge_formatter(lexer) Highlighter::Formatter.new(lexer.tag) end |