Class: SyncReadme::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/sync_readme/reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Reader

Returns a new instance of Reader.



5
6
7
8
9
10
# File 'lib/sync_readme/reader.rb', line 5

def initialize(config)
  @file_contents = File.read(config.filename)
  @notice = config.notice
  @strip_title = config.strip_title?
  @highlighter = config.syntax_highlighting? ? 'coderay' : nil
end

Instance Method Details

#htmlObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sync_readme/reader.rb', line 12

def html
  markdown = @file_contents
  markdown.sub!(/# .*\n/, '') if @strip_title
  options = {
    input: 'GFM',
    syntax_highlighter: @highlighter,
    syntax_highlighter_opts: {
      css: 'style',
      line_numbers: 'table'
    }
  }
  value = Kramdown::Document.new(markdown, options).to_html
  value = "#{@notice}#{value}" if @notice
  value
end