Class: AsciidoctorCommentLinks::CommentLinksRougeAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor-comment-links.rb

Instance Method Summary collapse

Instance Method Details

#create_formatter(node, source, lang, opts) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/asciidoctor-comment-links.rb', line 7

def create_formatter node, source, lang, opts
  formatter = super
  formatter.singleton_class.prepend (Module.new do
    def safe_span tok, safe_val
      if tok.token_chain[0].matches? ::Rouge::Token::Tokens::Comment
        safe_val = safe_val.gsub %r/https?:\/\/\S+/, '<a href="\&" target="_blank">\&</a>'
      end
      super
    end
  end)
  formatter
end