Method: MaRuKu::MDElement#replace_each_string

Defined in:
lib/maruku/structures_iterators.rb

#replace_each_string(&block) ⇒ Object

Apply passed block to each String in the hierarchy.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/maruku/structures_iterators.rb', line 40

def replace_each_string(&block)
	for c in @children
		if c.kind_of? MDElement
			c.replace_each_string(&block)
		end
	end

	processed = []
	until @children.empty?
		c = @children.shift
		if c.kind_of? String
			result = block.call(c)
			[*result].each do |e| processed << e end
		else
			processed << c
		end
	end
	@children = processed
end