Sha256: b67cfdd7e79b02ddbc2c461efe3a62cf8c61468ca5e8f3204aba5f6b40098e9c

Contents?: true

Size: 747 Bytes

Versions: 4

Compression:

Stored size: 747 Bytes

Contents

module ReverseMarkdown
  module Converters
    class Pre < Base
      def convert(node)
        if ReverseMarkdown.config.github_flavored
          "\n```#{language(node)}\n" << node.text.strip << "\n```\n"
        else
          "\n\n    " << node.text.strip.lines.to_a.join("    ") << "\n\n"
        end
      end

      private

      def language(node)
        lang = language_from_highlight_class(node)
        lang || language_from_confluence_class(node)
      end

      def language_from_highlight_class(node)
        node.parent['class'].to_s[/highlight-([a-zA-Z0-9]+)/, 1]
      end

      def language_from_confluence_class(node)
        node['class'].to_s[/brush:\s?(:?.*);/, 1]
      end
    end

    register :pre, Pre.new
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
reverse_markdown-0.8.2 lib/reverse_markdown/converters/pre.rb
reverse_markdown-0.8.1 lib/reverse_markdown/converters/pre.rb
reverse_markdown-0.8.0 lib/reverse_markdown/converters/pre.rb
reverse_markdown-0.7.0 lib/reverse_markdown/converters/pre.rb