Class HTML5::Filters::WhitespaceFilter
In: lib/feed_tools/vendor/html5/lib/html5/filters/whitespace.rb
Parent: Base

Methods

each  

Constants

SPACE_PRESERVE_ELEMENTS = %w[pre textarea] + RCDATA_ELEMENTS
SPACES = /[#{SPACE_CHARACTERS.join('')}]+/m

Public Instance methods

[Source]

    # File lib/feed_tools/vendor/html5/lib/html5/filters/whitespace.rb, line 11
11:       def each
12:         preserve = 0
13:         __getobj__.each do |token|
14:           case token[:type]
15:           when :StartTag
16:             if preserve > 0 or SPACE_PRESERVE_ELEMENTS.include?(token[:name])
17:               preserve += 1
18:             end
19: 
20:           when :EndTag
21:             preserve -= 1 if preserve > 0
22: 
23:           when :SpaceCharacters
24:             token[:data] = " " if preserve == 0 && token[:data]
25: 
26:           when :Characters
27:             token[:data] = token[:data].sub(SPACES,' ') if preserve == 0
28:           end
29: 
30:           yield token
31:         end
32:       end

[Validate]