Module: YARD::Redcarpet::Ext

Defined in:
lib/yard/redcarpet/ext.rb,
lib/yard/redcarpet/ext/version.rb

Constant Summary collapse

CONFIG_FILE =
'.yard_redcarpet_ext'.freeze
ENV_VAR =
'YARD_REDCARPET_EXTS'.freeze
DEFAULT_REDCARPET_EXTS =
%w[
  no_intraemphasis
  gh_blockcode
  fenced_code
  autolink
  tables
].freeze
VERSION =
"0.0.3".freeze

Class Method Summary collapse

Class Method Details

.exts_from_configObject



19
20
21
22
# File 'lib/yard/redcarpet/ext.rb', line 19

def self.exts_from_config
  return []  unless File.readable?(CONFIG_FILE)
  IO.read(CONFIG_FILE).split(/(?:\s*,\s*)|\n/)
end

.exts_from_envObject



24
25
26
27
28
# File 'lib/yard/redcarpet/ext.rb', line 24

def self.exts_from_env
  val = ENV[ENV_VAR]
  return []  unless val
  val.split(/\s*,\s*/)
end

.installObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/yard/redcarpet/ext.rb', line 51

def self.install
  YARD::Templates::Helpers::HtmlHelper.module_eval do
    alias :html_markup_markdown_noredcarpet :html_markup_markdown

    # Converts Markdown to HTML
    # @param [String] text input Markdown text
    # @return [String] output HTML
    # @since 0.6.0
    def html_markup_markdown(text)
      provider = markup_class(:markdown)
      if provider.to_s == 'RedcarpetCompat'
        redcarpet_exts = YARD::Redcarpet::Ext.redcarpet_exts
        provider.new(text, *redcarpet_exts).to_html
      else
        html_markup_markdown_noredcarpet(text)
      end
    end
  end
end

.redcarpet_extsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/yard/redcarpet/ext.rb', line 30

def self.redcarpet_exts
  @redcarpet_exts ||= begin
    exts = []
    exts_to_remove = []
    exts += DEFAULT_REDCARPET_EXTS
    exts += exts_from_config
    exts += exts_from_env
    exts = exts.uniq.select { |ext| !ext.empty? }
    exts.each do |ext|
      if ext =~ /\A\-(.+)\z/
        exts_to_remove << $1
      end
    end          
    exts.delete_if { |elem| elem =~ /\A\-/ }
    exts_to_remove.each do |ext_to_remove|
      exts.delete_if { |elem| elem == ext_to_remove }
    end
    exts.map { |ext| ext.to_sym }
  end
end