class Jekyll::OrgModeConverter

Public Instance Methods

convert(content) click to toggle source
# File lib/jekyll-org-to-html.rb, line 44
def convert(content)
  elisp_script = Tempfile.new 'org-to-html-elisp'
  elisp_script.write ELISP
  elisp_script.rewind

  content_as_file = Tempfile.new
  content_as_file.write content
  content_as_file.rewind

  # Run our elisp script and receive any errors from stdout
  out = `emacs --batch --load '#{elisp_script.path}' --eval '(org->html \"#{content_as_file.path}\")' 2>&1`
  # 2>&1 means redirect stderr to stdout
  # Emacs in `--batch` mode sends output to stderr instead of stdout
  raise "Emacs rejected your org-mode file: #{out}" unless
    $?.exitstatus.zero?

  # Remove the temp files
  elisp_script.unlink
  content_as_file.unlink

  # The elisp script saves the output in this named temp file
  # Warning: possible race condition if Jekyll ever parallelizes conversion
  # Don't change the name of this temp file without also changing
  # it in the elisp code above.
  File.open("/tmp/org-to-html", "r").read
end
matches(ext) click to toggle source
# File lib/jekyll-org-to-html.rb, line 36
def matches(ext)
  ext =~ /^\.org$/i
end
output_ext(ext) click to toggle source
# File lib/jekyll-org-to-html.rb, line 40
def output_ext(ext)
  ".html"
end