class Sass::Tree::Visitors::ToCss
def format_custom_property_value(node)
-
(String)
-
Parameters:
-
node
(Sass::Script::Tree::PropNode
) -- A custom property node.
def format_custom_property_value(node) value = node.resolved_value.sub(/\n[ \t\r\f\n]*\Z/, ' ') if node.style == :compact || node.style == :compressed || !value.include?("\n") # Folding not involving newlines was done in the parser. We can safely # fold newlines here because tokens like strings can't contain literal # newlines, so we know any adjacent whitespace is tokenized as whitespace. return node.resolved_value.gsub(/[ \t\r\f]*\n[ \t\r\f\n]*/, ' ') end # Find the smallest amount of indentation in the custom property and use # that as the base indentation level. lines = value.split("\n") indented_lines = lines[1..-1] min_indentation = indented_lines. map {|line| line[/^[ \t]*/]}. reject {|line| line.empty?}. min_by {|line| line.length} # Limit the base indentation to the same indentation level as the node name # so that if *every* line is indented relative to the property name that's # preserved. if node.name_source_range base_indentation = min_indentation[0...node.name_source_range.start_pos.offset - 1] end lines.first + "\n" + indented_lines.join("\n").gsub(/^#{base_indentation}/, ' ' * @tabs) end