blob: fe665ab8ec32b8b36aa25d50f794dfcebaaf05b0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# https://gist.github.com/sp301415/db9f7bee03bda483aa2ca7c0ca92fbfa
require 'kramdown/parser/kramdown'
require 'kramdown-parser-gfm'
class Kramdown::Parser::GFMKatex < Kramdown::Parser::GFM
# Override inline math parser
@@parsers.delete(:inline_math)
INLINE_MATH_START = /(\$+)([^\$]+)(\$+)/m
def parse_inline_math
start_line_number = @src.current_line_number
@src.pos += @src.matched_size
@tree.children << Element.new(:math, @src.matched[1..-2], nil, category: :span, location: start_line_number)
end
define_parser(:inline_math, INLINE_MATH_START, '\$')
end
|