-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to use codecogs for Latex in RSS
Refs #50
- Loading branch information
Showing
2 changed files
with
30 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Title: codecogs plugin | ||
# Author: Carl Boettiger, @cboettig | ||
# License: MIT | ||
# | ||
# A simple filter to replace mathjax-latex syntax with images of the | ||
# equations as rendered by codecogs. This is useful to filter content | ||
# entered into the atom feed, where javascript and css-based rendering | ||
# of equations won't work. | ||
|
||
# Credits to Noam Ross http://www.noamross.net/blog/2012/4/4/math-in-rss-feeds.html for inspiring this approach and to | ||
# helpful folks on SO for the regexpr: http://stackoverflow.com/questions/13166112/ruby-regexp-to-replace-equations | ||
|
||
# Example use: | ||
# | ||
# {{ post.content | codecogs }} | ||
# | ||
|
||
module Jekyll | ||
module ImageFilter | ||
def codecogs(input) | ||
# puts "generating images for equations in RSS feed with codecogs.rb" | ||
desired = input.gsub(/\\\[\s*(.*?)\s*\\\]/, "<div style=\"text-align:center;\"><img src=\"http://latex.codecogs.com/png.latex?\\1\" alt=\"\\1\" /></div>") | ||
desired.gsub(/\\\(\s*(.*?)\s*\\\)/, "<img src=\"http://latex.codecogs.com/png.latex?\\1\\inline\"/>") | ||
end | ||
end | ||
end | ||
Liquid::Template.register_filter(Jekyll::ImageFilter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters