diff options
Diffstat (limited to 'lib/yaml/baseemitter.rb')
-rw-r--r-- | lib/yaml/baseemitter.rb | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/lib/yaml/baseemitter.rb b/lib/yaml/baseemitter.rb index 007ee7be5e..1072f75533 100644 --- a/lib/yaml/baseemitter.rb +++ b/lib/yaml/baseemitter.rb @@ -36,28 +36,36 @@ module YAML def node_text( value, block = '>' ) @seq_map = false valx = value.dup - if options(:UseBlock) - block = '|' - elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/ - block = '|' - end - str = block.dup - if valx =~ /\n\Z\n/ - str << "+" - elsif valx =~ /\Z\n/ - else - str << "-" - end + unless block + block = + if options(:UseBlock) + '|' + elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/ + '|' + else + '>' + end + block += + if valx =~ /\n\Z\n/ + "+" + elsif valx =~ /\Z\n/ + "" + else + "-" + end + if valx =~ /\A[ \t#]/ + block += options(:Indent).to_s + end + end if valx =~ /#{YAML::ESCAPE_CHAR}/ valx = YAML::escape( valx ) end - if valx =~ /\A[ \t#]/ - str << options(:Indent).to_s - end - if block == '>' + if block[0] == ?> valx = fold( valx ) end - self << str + indent_text( valx ) + "\n" + indt = nil + indt = $&.to_i if block =~ /\d+/ + self << block + indent_text( valx, indt ) + "\n" end # @@ -85,9 +93,9 @@ module YAML # # Write a text block with the current indent # - def indent_text( text ) + def indent_text( text, indt = nil ) return "" if text.to_s.empty? - spacing = " " * ( level * options(:Indent) ) + spacing = " " * ( level * ( indt || options(:Indent) ) ) return "\n" + text.gsub( /^([^\n])/, "#{spacing}\\1" ) end |