Sha256: 9106a134382377dec57c1a660cc4f22e6c9263a42ccbf4518df2868d766ba0fa

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

# KaTeX support for Kramdown < v1.17.0 (newer versions have built-in support).

module Thredded
  module MarkdownKatex
    module Kramdown
      # The KaTeX converter engine for Kramdown.
      module KatexConverter
        # rubocop:disable Metrics/AbcSize,Metrics/MethodLength

        def self.call(converter, el, opts)
          display_mode = el.options[:category] == :block
          result = ::Katex.render(
            el.value,
            display_mode: display_mode,
            throw_on_error: false,
            **converter.options[:math_engine_opts]
          )
          attr = el.attr.dup
          attr.delete('xmlns')
          attr.delete('display')
          result
            .insert(result =~ /[[:space:]>]/, converter.html_attributes(attr))
          result = "#{' ' * opts[:indent]}#{result}\n" if display_mode
          result
        end
        # rubocop:enable Metrics/AbcSize,Metrics/MethodLength
      end
    end
  end
end

require 'kramdown/converter'
Kramdown::Converter
  .add_math_engine(:katex, ::Thredded::MarkdownKatex::Kramdown::KatexConverter)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
thredded-markdown_katex-0.4.2 lib/thredded/markdown_katex/kramdown/katex_converter.rb
thredded-markdown_katex-0.4.1 lib/thredded/markdown_katex/kramdown/katex_converter.rb
thredded-markdown_katex-0.4.0 lib/thredded/markdown_katex/kramdown/katex_converter.rb
thredded-markdown_katex-0.3.1 lib/thredded/markdown_katex/kramdown/katex_converter.rb
thredded-markdown_katex-0.3.0 lib/thredded/markdown_katex/kramdown/katex_converter.rb