Sha256: ba6f70a6c1ec5ede8d09fafc09d0fec2adf86a771aef1992c37b831b6f02b601
Contents?: true
Size: 852 Bytes
Versions: 6
Compression:
Stored size: 852 Bytes
Contents
module Slacken::Filters # Public: Group inline elements and wrap them in a wrapper node. # Wrapper nodes are introduced to group inline nodes in a paragraph. class GroupInlines < Slacken::Filter def call(component) if component.block? component.derive(group_component(component)) else component.derive(component.children.map(&method(:call))) end end def valid?(component) if component.type.member_of?(:wrapper) true elsif component.inline? false else component.children.all?(&method(:valid?)) end end private def group_component(component) component.children.map(&method(:call)).chunk(&:inline?).map do |is_inline, group| is_inline ? component.class.new(:wrapper, group) : group end.flatten end end end
Version data entries
6 entries across 6 versions & 1 rubygems