Module: Thredded::MarkdownKatex

Defined in:
lib/thredded/markdown_katex.rb,
lib/thredded/markdown_katex/railtie.rb,
lib/thredded/markdown_katex/version.rb,
lib/thredded/markdown_katex/svg_whitelist.rb,
lib/thredded/markdown_katex/mathml_whitelist.rb,
lib/thredded/markdown_katex/email_transformer.rb,
lib/thredded/markdown_katex/kramdown/katex_converter.rb,
lib/generators/thredded/markdown_katex/install_generator.rb

Overview

Adds TeX math support to Thredded markdown via KaTeX.

Defined Under Namespace

Modules: Kramdown, MathMLWhitelist, SVGWhitelist Classes: EmailTransformer, InstallGenerator, Railtie

Constant Summary collapse

KRAMDOWN_FILTER_CLASS_NAME =
'Thredded::HtmlPipeline::KramdownFilter'
VERSION =
'1.0.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optionsObject (readonly)

Returns the value of attribute options.



21
22
23
# File 'lib/thredded/markdown_katex.rb', line 21

def options
  @options
end

Class Method Details

.setup!Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/thredded/markdown_katex.rb', line 23

def setup! # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  if pipeline_contains?(KRAMDOWN_FILTER_CLASS_NAME)
    # KaTeX engine for versions of Kramdown that do not have it built-in:
    if Gem::Version.new(Kramdown::VERSION) < Gem::Version.new('1.17.0')
      require 'thredded/markdown_katex/kramdown/katex_converter'
    else
      require 'kramdown-math-katex'
    end
    Thredded::HtmlPipeline::KramdownFilter.options.update(options)
  else
    raise "#{self.class.name} requires #{KRAMDOWN_FILTER_CLASS_NAME} " \
          'in Thredded::ContentFormatter.pipeline_filters'
  end

  configure_whitelist!

  Thredded::EmailTransformer.transformers <<
    Thredded::MarkdownKatex::EmailTransformer

  Thredded::FormattingDemoContent.parts.unshift File.read(
    File.join(File.dirname(__FILE__), 'markdown_katex', 'demo.md')
  )
end