Skip to content

Commit 144da72

Browse files
committed
Include Jekyll plugins
1 parent 1c999ac commit 144da72

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

_plugins/eq.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Author: Trevor Bedford
2+
# License: MIT
3+
4+
module Jekyll
5+
class Eq < Liquid::Tag
6+
def initialize(tag_name, markup, tokens)
7+
super
8+
@markup = "#{markup}".strip
9+
end
10+
def render(context)
11+
12+
require 'execjs'
13+
14+
parsed = Liquid::Template.parse(@markup).render context
15+
16+
katexsrc = open("./js/katex.min.js").read
17+
@katex = ExecJS.compile(katexsrc)
18+
19+
style = "text-align: center; margin-top: 0.5em; margin-bottom: 0.5em;"
20+
div_open = "<div style='#{style}'>"
21+
parsed = "\\displaystyle " + parsed
22+
div_close = "</div>"
23+
output = div_open + eqn_to_html(parsed) + div_close
24+
25+
return output
26+
27+
end
28+
def eqn_to_html(string)
29+
return @katex.call("katex.renderToString", string, { displayMode: true })
30+
end
31+
end
32+
end
33+
34+
Liquid::Template.register_tag('eq', Jekyll::Eq)

_plugins/eqinline.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Author: Trevor Bedford
2+
# License: MIT
3+
4+
module Jekyll
5+
class EqInline < Liquid::Tag
6+
def initialize(tag_name, markup, tokens)
7+
super
8+
@markup = "#{markup}".strip
9+
end
10+
def render(context)
11+
12+
require 'execjs'
13+
14+
parsed = Liquid::Template.parse(@markup).render context
15+
16+
katexsrc = open("./js/katex.min.js").read
17+
@katex = ExecJS.compile(katexsrc)
18+
return eqn_to_html(parsed)
19+
20+
end
21+
def eqn_to_html(string)
22+
return @katex.call("katex.renderToString", string)
23+
end
24+
end
25+
end
26+
27+
Liquid::Template.register_tag('eqinline', Jekyll::EqInline)

0 commit comments

Comments
 (0)