Class: Jekyll::WikiRefs::WebLinkConverter

Inherits:
Converter
  • Object
show all
Defined in:
lib/jekyll-wikirefs/plugins/converter.rb

Constant Summary collapse

CSS_KEY =

config

"css"
CONFIG_KEY =
"wikirefs"
EXCLUDE_KEY =
"exclude"

Instance Method Summary collapse

Instance Method Details

#convert(content) ⇒ Object

add ‘web-link’ css class to links that aren’t

  • wikilinks

  • contain an excluded css class



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jekyll-wikirefs/plugins/converter.rb', line 31

def convert(content)
  excluded_classes = option_css(EXCLUDE_KEY)
  if excluded_classes.nil? || excluded_classes.empty?
    css_def = "a:not(.#{$wiki_conf.css_name("wiki")}):not(.#{$wiki_conf.css_name("embed_wiki_link")})"
  else
    css_def = "a:not(.#{$wiki_conf.css_name("wiki")}):not(.#{$wiki_conf.css_name("embed_wiki_link")}):not(.#{excluded_classes.join("):not(.")})"
  end
  parsed_content = Nokogiri::HTML::fragment(content)
  parsed_content.css(css_def).each do |link|
    link.add_class('web-link')
  end
  content = parsed_content.to_html
end

#matches(ext) ⇒ Object

link types WEB_KEY = “web” WIKIL_KEY = “wiki” INVALID_KEY = “invalid” WIKI_EMBED_KEY = “wiki_embed”



20
21
22
# File 'lib/jekyll-wikirefs/plugins/converter.rb', line 20

def matches(ext)
  ext =~ /^\.md$/i
end

#option_css(key) ⇒ Object

config helpers



47
48
49
# File 'lib/jekyll-wikirefs/plugins/converter.rb', line 47

def option_css(key)
  @config[CONFIG_KEY] && @config[CONFIG_KEY][CSS_KEY] && @config[CONFIG_KEY][CSS_KEY][key]
end

#output_ext(ext) ⇒ Object



24
25
26
# File 'lib/jekyll-wikirefs/plugins/converter.rb', line 24

def output_ext(ext)
  ".html"
end