class Octodown::Renderer::GithubMarkdown

Attributes

file[R]
logger[R]
options[R]

Public Class Methods

new(file, options = {}) click to toggle source
# File lib/octodown/renderer/github_markdown.rb, line 16
def initialize(file, options = {})
  @file = file
  @options = options
  @logger = options[:logger]
end

Public Instance Methods

content() click to toggle source
# File lib/octodown/renderer/github_markdown.rb, line 22
def content
  if file == STDIN
    buffer = file.read
  else
    begin
      File.open(file.path, 'r') { |f| buffer = f.read }
    rescue Errno::ENOENT
      logger.warn 'Something went wrong when trying to open the file'
    end
  end
  pipeline.call(buffer ||= 'could not read changes')[:output].to_s
end

Private Instance Methods

context() click to toggle source
# File lib/octodown/renderer/github_markdown.rb, line 37
def context
  {
    asset_root: 'https://github.githubassets.com/images/icons/',
    server: options[:presenter] == :server,
    original_document_root: document_root,
    scope: 'highlight',
    gfm: options[:gfm] || false
  }
end
document_root() click to toggle source
# File lib/octodown/renderer/github_markdown.rb, line 59
def document_root
  case file
  when STDIN then Dir.pwd
  else File.dirname File.expand_path(file.path)
  end
end
pipeline() click to toggle source
# File lib/octodown/renderer/github_markdown.rb, line 47
def pipeline
  Pipeline.new [
    Pipeline::MarkdownFilter,
    Pipeline::SyntaxHighlightFilter,
    Support::RelativeRootFilter,
    Pipeline::ImageMaxWidthFilter,
    Pipeline::MentionFilter,
    Pipeline::EmojiFilter,
    TaskList::Filter
  ], context
end