class Jazzy::Markdown::JazzyHTML

rubocop:disable Metrics/ClassLength

Constants

DOCC_CALLOUTS

List from developer.apple.com/documentation/xcode/formatting-your-documentation-content#Add-Notes-and-Other-Asides

DOCC_CALLOUT_REGEX
ELIDED_LI_TOKEN
GENERAL_CALLOUTS
SPECIAL_LIST_TYPES
SPECIAL_LIST_TYPE_REGEX
UNIQUELY_HANDLED_CALLOUTS

List from github.com/apple/swift/blob/master/include/swift/Markup/SimpleFields.def

Attributes

default_language[RW]

Public Instance Methods

block_code(code, language) click to toggle source
Calls superclass method
# File lib/jazzy/jazzy_markdown.rb, line 190
def block_code(code, language)
  super(code, language || default_language)
end
block_quote(html) click to toggle source
# File lib/jazzy/jazzy_markdown.rb, line 181
def block_quote(html)
  if html =~ DOCC_CALLOUT_REGEX
    type = Regexp.last_match[1]
    render_aside(type, html.sub(/#{Regexp.escape(type)}:\s*/, ''))
  else
    "\n<blockquote>\n#{html}</blockquote>\n"
  end
end
codespan(text) click to toggle source
# File lib/jazzy/jazzy_markdown.rb, line 67
def codespan(text)
  case text
  when /^\$\$(.*)\$\$$/m
    o = ["</p><div class='math m-block'>",
         Regexp.last_match[1],
         '</div><p>']
    Markdown.has_math = true
  when /^\$(.*)\$$/m
    o = ["<span class='math m-inline'>", Regexp.last_match[1], '</span>']
    Markdown.has_math = true
  else
    o = ['<code>', text.to_s, '</code>']
  end

  o[0] + CGI.escapeHTML(o[1]) + o[2]
end
header(text, header_level) click to toggle source
# File lib/jazzy/jazzy_markdown.rb, line 56
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) click to toggle source
# File lib/jazzy/jazzy_markdown.rb, line 156
def list(text, list_type)
  elided = text.gsub!(ELIDED_LI_TOKEN, '')
  return if text =~ /\A\s*\Z/ && elided

  tag = list_type == :ordered ? 'ol' : 'ul'
  "\n<#{tag}>\n#{text}</#{tag}>\n"
    .gsub(%r{\n?<ul>\n?</ul>}, '')
end
list_item(text, _list_type) click to toggle source
# File lib/jazzy/jazzy_markdown.rb, line 130
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_list_aside(type,
                             text.sub(/#{Regexp.escape(type)}:\s+/, ''))
  end
  "<li>#{text.strip}</li>\n"
end
render_aside(type, text) click to toggle source
# File lib/jazzy/jazzy_markdown.rb, line 147
      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
render_list_aside(type, text) click to toggle source
# File lib/jazzy/jazzy_markdown.rb, line 143
def render_list_aside(type, text)
  "</ul>#{render_aside(type, text).chomp}<ul>\n"
end
rouge_formatter(lexer) click to toggle source
# File lib/jazzy/jazzy_markdown.rb, line 194
def rouge_formatter(lexer)
  Highlighter::Formatter.new(lexer.tag)
end