lib/maruku/element.rb in maruku-0.7.2 vs lib/maruku/element.rb in maruku-0.7.3

- old
+ new

@@ -84,12 +84,12 @@ @children.each do |c| if c.is_a? MDElement then yield c if e_node_type.nil? || c.node_type == e_node_type c.each_element(e_node_type, &block) # - # This handles the case where the children of an - # element are arranged in a multi-dimensional array + # This handles the case where the children of an + # element are arranged in a multi-dimensional array # (as in the case of a table) elsif c.is_a? Array then c.each do |cc| # A recursive call to each_element will ignore the current element # so we handle this case inline @@ -110,18 +110,29 @@ # This destructively modifies this node and its children. # # @todo Make this non-destructive def replace_each_string(&block) @children.map! do |c| - next yield c unless c.is_a?(MDElement) + next yield c if c.is_a?(String) c.replace_each_string(&block) c - end.flatten! + end + @children.flatten! unless self.node_type == :table end end # A specialization of Element that can keep track of # its parsed HTML as an attribute (rather than metadata) class MDHTMLElement < MDElement attr_accessor :parsed_html # HTMLFragment + end +end + +class Array + def replace_each_string(&block) + self.map! do |c| + next yield c if c.is_a?(String) + c.replace_each_string(&block) + c + end end end