Sha256: 84cdd548554a97ecc328380938a74a2f740f4b337ca9f35422513d2ececbb2c8

Contents?: true

Size: 968 Bytes

Versions: 12

Compression:

Stored size: 968 Bytes

Contents

# frozen_string_literal: true
module Asciidoctor
class SyntaxHighlighter::PrettifyAdapter < SyntaxHighlighter::Base
  register_for 'prettify'

  def initialize *args
    super
    @pre_class = 'prettyprint'
  end

  def format node, lang, opts
    opts[:transform] = proc {|pre| pre['class'] += %( #{(start = node.attr 'start') ? %[linenums:#{start}] : 'linenums'}) } if node.attr? 'linenums'
    super
  end

  def docinfo? location
    true
  end

  def docinfo location, doc, opts
    base_url = doc.attr 'prettifydir', %(#{opts[:cdn_base_url]}/prettify/r298)
    if location == :head
      prettify_theme_url = ((prettify_theme = doc.attr 'prettify-theme', 'prettify').start_with? 'http://', 'https://') ? prettify_theme : %(#{base_url}/#{prettify_theme}.min.css)
      %(<link rel="stylesheet" href="#{prettify_theme_url}"#{opts[:self_closing_tag_slash]}>)
    else # :footer
      %(<script src="#{base_url}/run_prettify.min.js"></script>)
    end
  end
end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
asciidoctor-2.0.22 lib/asciidoctor/syntax_highlighter/prettify.rb
asciidoctor-2.0.21 lib/asciidoctor/syntax_highlighter/prettify.rb
asciidoctor-2.0.20 lib/asciidoctor/syntax_highlighter/prettify.rb
asciidoctor-2.0.19 lib/asciidoctor/syntax_highlighter/prettify.rb
asciidoctor-2.0.18 lib/asciidoctor/syntax_highlighter/prettify.rb
asciidoctor-2.0.17 lib/asciidoctor/syntax_highlighter/prettify.rb
asciidoctor-2.0.16 lib/asciidoctor/syntax_highlighter/prettify.rb
asciidoctor-2.0.15 lib/asciidoctor/syntax_highlighter/prettify.rb
asciidoctor-2.0.14 lib/asciidoctor/syntax_highlighter/prettify.rb
asciidoctor-2.0.13 lib/asciidoctor/syntax_highlighter/prettify.rb
asciidoctor-2.0.12 lib/asciidoctor/syntax_highlighter/prettify.rb
asciidoctor-2.0.11 lib/asciidoctor/syntax_highlighter/prettify.rb