Sha256: fe715d10407881bf484ca377b5d08cd368b22a3d0323c5e6b5e5def1a313557c

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require "asciimath"


$ASCIIMATH_CSS = File.join(Gem::Specification.find_by_name("asciimath").gem_dir, "style", "math.css")


Jekyll::Hooks.register :site, :post_write do |site|
  site_asciimath_css_path = site.config['asciimath_css_path'] || 'assets/math.css'
  target = File.join(site.config['destination'] || '_site', site_asciimath_css_path)
  system("cp #{$ASCIIMATH_CSS} #{target}")
end


module Jekyll::AsciiMathFilter
  def asciimath(input)
    delimiter = @context.registers[:site].config['asciimath_delimiter'] || '$$'
    delim_regex = Regexp.quote(delimiter)
    asciimath_regex = Regexp.new("(?<=#{delim_regex})[^#{delim_regex}]+(?=#{delim_regex})")

    if input.scan(asciimath_regex).size > 0
      pieces = "#{delimiter} #{input} #{delimiter}".scan(asciimath_regex)
      parsed_pieces = []

      pieces.each_with_index { |piece, idx|
        if idx.odd?
          parsed_pieces << AsciiMath.parse(piece).to_html
        elsif piece != ' '
          parsed_pieces << piece
        end
      }
      return parsed_pieces.join('')
    else
      return input
    end
  end
end

Liquid::Template.register_filter(Jekyll::AsciiMathFilter)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-asciimath-1.0.0 lib/jekyll_asciimath/jekyll_asciimath.rb