Class: Remark

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

Constant Summary collapse

IGNORE =
%w(script head style)
BLOCK =
%w(p blockquote h1 h2 h3 h4 h5 h6 pre)

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Remark

Returns a new instance of Remark.



4
5
6
# File 'lib/remark.rb', line 4

def initialize(source)
  @doc = Hpricot(source)
end

Instance Method Details

#scopeObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/remark.rb', line 12

def scope
  if body = @doc.at('/html/body')
    candidates = (body / 'p').inject(Hash.new(0)) do |memo, para|
      memo[para.parent] += 1
      memo
    end.invert
    
    candidates[candidates.keys.max]
  else
    @doc
  end
end

#to_markdownObject



8
9
10
# File 'lib/remark.rb', line 8

def to_markdown
  remark_block(scope)
end