Created
May 23, 2016 22:04
-
-
Save worace/506dbd1acbeeee4889e1bdfd30764977 to your computer and use it in GitHub Desktop.
Jekyll Org Mode Experiments
This file contains hidden or 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
# https://gist.github.com/abhiyerra/7377603 | |
module Jekyll | |
# Convert org-mode files. | |
require 'org-ruby' | |
class OrgConverter < Converter | |
safe true | |
def setup | |
# No-op | |
end | |
def matches(ext) | |
puts "CHEECKING ORG: #{ext}" | |
ext =~ /\.org$/i | |
end | |
def output_ext(ext) | |
".html" | |
end | |
def convert(content) | |
setup | |
Orgmode::Parser.new(content).to_html | |
end | |
end | |
end |
This file contains hidden or 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
# https://github.com/eggcaker/jekyll-org | |
require 'org-ruby' | |
if Jekyll::VERSION < "3.0" | |
raise Jekyll::FatalException, "This version of jekyll-org is only compatible with Jekyll v3 and above." | |
end | |
module Jekyll | |
class OrgConverter < Converter | |
safe true | |
priority :low | |
def matches(ext) | |
ext =~ /xxxxxxxxxxxxxxxxxx/i | |
end | |
def output_ext(ext) | |
".html" | |
end | |
def convert(content) | |
content | |
end | |
end | |
module Filters | |
def restify(input) | |
site = @context.registers[:site] | |
converter = site.find_converter_instance(Jekyll::OrgConverter) | |
converter.convert(input) | |
end | |
end | |
# This overrides having to use YAML in the posts. | |
# Instead use settings from Org mode. | |
class Document | |
alias :_orig_read :read | |
def read(opts = {}) | |
unless relative_path.end_with?(".org") | |
return _orig_read(opts) | |
end | |
Jekyll.logger.debug "Reading:", relative_path | |
self.content = File.read(path, Utils.merged_file_read_opts(site, opts)) | |
self.data ||= {} | |
liquid_enabled = false | |
org_text = Orgmode::Parser.new(content, { markup_file: "html.tags.yml" }) | |
org_text.in_buffer_settings.each_pair do |key, value| | |
# Remove #+TITLE from the buffer settings to avoid double exporting | |
org_text.in_buffer_settings.delete(key) if key =~ /title/i | |
buffer_setting = key.downcase | |
if buffer_setting == 'liquid' | |
liquid_enabled = true | |
end | |
self.data[buffer_setting] = value | |
end | |
# Disable Liquid tags from the output by default or enabled with liquid_enabled tag | |
if liquid_enabled | |
self.content = org_text.to_html | |
self.content = self.content.gsub("‘","'") | |
self.content = self.content.gsub("’", "'") | |
else | |
self.content = <<ORG | |
{% raw %} | |
#{org_text.to_html} | |
{% endraw %} | |
ORG | |
end | |
post_read | |
rescue => e | |
puts "Error converting file #{relative_path}: #{e.message} #{e.backtrace}" | |
end | |
end | |
end |
This file contains hidden or 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
# http://joelmccracken.github.io/entries/org-mode-jekyll-plugin/ | |
module Jekyll | |
class EmacsConverter < Converter | |
safe true | |
priority :low | |
def matches(ext) | |
ext =~ /\.org$/i | |
end | |
def output_ext(ext) | |
".html" | |
end | |
def convert(content) | |
puts "************CONVERTING EMACS ORG**************" | |
inread, inwrite = IO.pipe | |
outread, outwrite = IO.pipe | |
inwrite.write content | |
inwrite.close | |
emacs_execution_string = "emacs -Q --batch -L " \ | |
"_vendor/org-8.2.6/lisp/ -l _lib/htmlize.el -l _lib/org-convert.el -f compile-org-file" | |
org_pid = spawn(emacs_execution_string, :in => inread, :out => outwrite, :err => :out) | |
inread.close | |
outwrite.close | |
Process.wait(org_pid) | |
out_content = outread.read | |
outread.close | |
out_content | |
end | |
end | |
end |
This file contains hidden or 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
(require 'org) | |
(require 'ox) | |
(require 'ox-html) | |
;; (require 'htmlize) | |
;; (setq org-src-fontify-natively t) | |
(defun compile-org-file () | |
(interactive) | |
(let ((org-document-content "") | |
this-read) | |
(while (setq this-read (ignore-errors | |
(read-from-minibuffer ""))) | |
(setq org-document-content (concat org-document-content "\n" this-read))) | |
(with-temp-buffer | |
(org-mode) | |
(insert org-document-content) | |
(org-html-export-as-html nil nil nil t) | |
(princ (buffer-string))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment