Class: Redmine::WikiFormatting::Markdown::HTML

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Includes:
ActionView::Helpers::TagHelper, Helpers::URL
Defined in:
lib/redmine/wiki_formatting/markdown/formatter.rb

Instance Method Summary collapse

Methods included from Helpers::URL

#uri_with_link_safe_scheme?, #uri_with_safe_scheme?

Instance Method Details



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/redmine/wiki_formatting/markdown/formatter.rb', line 29

def autolink(link, link_type)
  if link_type == :email
    link("mailto:#{link}", nil, link) || CGI.escapeHTML(link)
  else
    content = link
    # Pretty printing: if we get an email address as an actual URI, e.g.
    # `mailto:[email protected]`, we don't want to print the `mailto:` prefix
    content = link[7..-1] if link.start_with?('mailto:')

    link(link, nil, content) || CGI.escapeHTML(link)
  end
end

#block_code(code, language) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/redmine/wiki_formatting/markdown/formatter.rb', line 52

def block_code(code, language)
  if language.present? && Redmine::SyntaxHighlighting.language_supported?(language)
    html = Redmine::SyntaxHighlighting.highlight_by_language(code, language)
    classattr = " class=\"#{CGI.escapeHTML language} syntaxhl\""
  else
    html = CGI.escapeHTML(code)
  end
  # original language for extension development
  langattr = " data-language=\"#{CGI.escapeHTML language}\"" if language.present?
  "<pre><code#{classattr}#{langattr}>#{html}</code></pre>"
end

#image(link, title, alt_text) ⇒ Object



64
65
66
67
68
# File 'lib/redmine/wiki_formatting/markdown/formatter.rb', line 64

def image(link, title, alt_text)
  return unless uri_with_safe_scheme?(link)

  tag('img', :src => link, :alt => alt_text || "", :title => title)
end


42
43
44
45
46
47
48
49
50
# File 'lib/redmine/wiki_formatting/markdown/formatter.rb', line 42

def link(link, title, content)
  return nil unless uri_with_link_safe_scheme?(link)

  css = nil
  unless link&.starts_with?('/') || link&.starts_with?('mailto:')
    css = 'external'
  end
  ('a', content.to_s.html_safe, :href => link, :title => title, :class => css)
end