lib/asciidoctor/syntax_highlighter.rb in asciidoctor-2.0.10 vs lib/asciidoctor/syntax_highlighter.rb in asciidoctor-2.0.11

- old
+ new

@@ -18,18 +18,19 @@ def initialize name, backend = 'html5', opts = {} @name = @pre_class = name end # Public: Indicates whether this syntax highlighter has docinfo (i.e., markup) to insert into the output document at - # the specified location. + # the specified location. Should be called by converter after main content has been converted. # # location - The Symbol representing the location slot (:head or :footer). # # Returns a [Boolean] indicating whether the docinfo method should be called for this location. def docinfo? location; end # Public: Generates docinfo markup for this syntax highlighter to insert at the specified location in the output document. + # Should be called by converter after main content has been converted. # # location - The Symbol representing the location slot (:head or :footer). # doc - The Document in which this syntax highlighter is being used. # opts - A Hash of options that configure the syntax highlighting: # :linkcss - A Boolean indicating whether the stylesheet should be linked instead of embedded (optional). @@ -137,11 +138,11 @@ # Public: Resolves the name to a syntax highlighter instance, if found in the registry. # # name - The String name of the syntax highlighter to create. # backend - The String name of the backend for which this syntax highlighter is being used (default: 'html5'). # opts - A Hash of options providing information about the context in which this syntax highlighter is used: - # :doc - The Document for which this syntax highlighter was created. + # :document - The Document for which this syntax highlighter was created. # # Returns a [SyntaxHighlighter] instance for the specified name. def create name, backend = 'html5', opts = {} if (syntax_hl = self.for name) syntax_hl = syntax_hl.new name, backend, opts if ::Class === syntax_hl @@ -233,12 +234,14 @@ include SyntaxHighlighter def format node, lang, opts class_attr_val = opts[:nowrap] ? %(#{@pre_class} highlight nowrap) : %(#{@pre_class} highlight) if (transform = opts[:transform]) - pre = { 'class' => class_attr_val } - code = lang ? { 'data-lang' => lang } : {} - transform[pre, code] + transform[(pre = { 'class' => class_attr_val }), (code = lang ? { 'data-lang' => lang } : {})] + # NOTE: make sure data-lang is the last attribute on the code tag to remain consistent with 1.5.x + if (lang = code.delete 'data-lang') + code['data-lang'] = lang + end %(<pre#{pre.map {|k, v| %[ #{k}="#{v}"] }.join}><code#{code.map {|k, v| %[ #{k}="#{v}"] }.join}>#{node.content}</code></pre>) else %(<pre class="#{class_attr_val}"><code#{lang ? %[ data-lang="#{lang}"] : ''}>#{node.content}</code></pre>) end end