Skip to content

Commit

Permalink
Include Jekyll plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
trvrb committed Mar 5, 2024
1 parent 1c999ac commit 144da72
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
34 changes: 34 additions & 0 deletions _plugins/eq.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Author: Trevor Bedford
# License: MIT

module Jekyll
class Eq < Liquid::Tag
def initialize(tag_name, markup, tokens)
super
@markup = "#{markup}".strip
end
def render(context)

require 'execjs'

parsed = Liquid::Template.parse(@markup).render context

katexsrc = open("./js/katex.min.js").read
@katex = ExecJS.compile(katexsrc)

style = "text-align: center; margin-top: 0.5em; margin-bottom: 0.5em;"
div_open = "<div style='#{style}'>"
parsed = "\\displaystyle " + parsed
div_close = "</div>"
output = div_open + eqn_to_html(parsed) + div_close

return output

end
def eqn_to_html(string)
return @katex.call("katex.renderToString", string, { displayMode: true })
end
end
end

Liquid::Template.register_tag('eq', Jekyll::Eq)
27 changes: 27 additions & 0 deletions _plugins/eqinline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Author: Trevor Bedford
# License: MIT

module Jekyll
class EqInline < Liquid::Tag
def initialize(tag_name, markup, tokens)
super
@markup = "#{markup}".strip
end
def render(context)

require 'execjs'

parsed = Liquid::Template.parse(@markup).render context

katexsrc = open("./js/katex.min.js").read
@katex = ExecJS.compile(katexsrc)
return eqn_to_html(parsed)

end
def eqn_to_html(string)
return @katex.call("katex.renderToString", string)
end
end
end

Liquid::Template.register_tag('eqinline', Jekyll::EqInline)

0 comments on commit 144da72

Please sign in to comment.