class Jekyll::Converters::Org

Public Class Methods

matches(ext) click to toggle source

true if current file is an org file

# File lib/jekyll-org/converter.rb, line 14
def self.matches(ext)
  ext =~ /org/i
end
matches_path(path) click to toggle source

matches, but accepts complete path

# File lib/jekyll-org/converter.rb, line 19
def self.matches_path(path)
  matches(File.extname(path))
end

Public Instance Methods

actually_convert(content) click to toggle source
# File lib/jekyll-org/converter.rb, line 37
def actually_convert(content)
  case content
  when Orgmode::Parser
    if liquid_enabled?(content)
      content.to_html.gsub("‘", "'").gsub("’", "'")
    else
      '{% raw %} ' + content.to_html + ' {% endraw %}'
    end
  else
    parser, variables = parse_org(content)
    convert(parser)
  end
end
convert(content) click to toggle source

because by the time an org file reaches the converter… it will have already been converted.

# File lib/jekyll-org/converter.rb, line 33
def convert(content)
  content
end
matches(ext) click to toggle source
# File lib/jekyll-org/converter.rb, line 23
def matches(ext)
  self.class.matches ext
end
output_ext(ext) click to toggle source
# File lib/jekyll-org/converter.rb, line 27
def output_ext(ext)
  '.html'
end
parse_org(content) click to toggle source
# File lib/jekyll-org/converter.rb, line 51
def parse_org(content)
  parser   = Orgmode::Parser.new(content, parser_options)
  settings = { :liquid => org_config.fetch("liquid", false) }

  parser.in_buffer_settings.each_pair do |key, value|
    # Remove #+TITLE from the buffer settings to avoid double exporting
    parser.in_buffer_settings.delete(key) if key =~ /title/i
    assign_setting(key, value, settings)
  end

  return parser, settings
end

Private Instance Methods

_parse_boolean(value, error_msg=nil) click to toggle source
# File lib/jekyll-org/converter.rb, line 111
def _parse_boolean(value, error_msg=nil)
  case value.downcase
  when *@@truthy_regexps
    true
  when *@@falsy_regexps
    false
  else
    unless error_msg.nil?
      Jekyll.logger.warn("OrgDocument:", error_msg + ": #{value}")
    end
  end
end
assign_setting(key, value, settings) click to toggle source
# File lib/jekyll-org/converter.rb, line 87
def assign_setting(key, value, settings)
  key = key.downcase

  case key
  when "liquid"
    value = _parse_boolean(value, "unknown LIQUID setting")
    settings[:liquid] = value unless value.nil?
  when "tags", "categories"
    # Parse a string of tags separated by spaces into a list.
    # Tags containing spaces can be wrapped in quotes,
    # e.g. '#+TAGS: foo "with spaces"'.
    #
    # The easiest way to do this is to use rubys builtin csv parser
    # and use spaces instead of commas as column separator.
    settings[key] = CSV::parse_line(value, col_sep: ' ')
  else
    value_bool = _parse_boolean(value)
    settings[key] = (value_bool.nil?) ? value : value_bool
  end
end
config_liquid_enabled?() click to toggle source
# File lib/jekyll-org/converter.rb, line 66
def config_liquid_enabled?
  org_config.fetch("liquid", false)
end
liquid_enabled?(parser) click to toggle source
# File lib/jekyll-org/converter.rb, line 70
def liquid_enabled?(parser)
  tuple = parser.in_buffer_settings.each_pair.find do |key, _|
    key =~ /liquid/i
  end

  if tuple.nil?
      config_liquid_enabled? # default value, as per config
  else
      _parse_boolean(tuple[1], "unknown LIQUID setting")
  end
end
parser_options() click to toggle source

see github.com/bdewey/org-ruby/blob/master/lib/org-ruby/parser.rb

# File lib/jekyll-org/converter.rb, line 83
def parser_options
  org_config.fetch("parser_options", { markup_file: 'html.tags.yml' })
end