aboutsummaryrefslogtreecommitdiffstats
path: root/lib/yaml/baseemitter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/yaml/baseemitter.rb')
-rw-r--r--lib/yaml/baseemitter.rb29
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/yaml/baseemitter.rb b/lib/yaml/baseemitter.rb
index 2881d424b4..1aef152749 100644
--- a/lib/yaml/baseemitter.rb
+++ b/lib/yaml/baseemitter.rb
@@ -47,7 +47,7 @@ module YAML
end
indt = $&.to_i if block =~ /\d+/
- if valx =~ /(\A[ \t#]|^---\s+)/
+ if valx =~ /(\A\n*[ \t#]|^---\s+)/
indt = options(:Indent) unless indt.to_i > 0
block += indt.to_s
end
@@ -61,14 +61,18 @@ module YAML
"-"
end
end
- if valx =~ /#{YAML::ESCAPE_CHAR}/
- valx = YAML::escape( valx )
- end
- if block[0] == ?>
- valx = fold( valx )
- end
- #p [block, indt]
- self << block + indent_text( valx, indt ) + "\n"
+ block += "\n"
+ if block[0] == ?"
+ esc_skip = ( "\t\n" unless valx =~ /^[ \t]/ ) || ""
+ valx = fold( YAML::escape( valx, esc_skip ) + "\"" ).chomp
+ self << '"' + indent_text( valx, indt, false )
+ else
+ if block[0] == ?>
+ valx = fold( valx )
+ end
+ #p [block, indt]
+ self << block + indent_text( valx, indt )
+ end
end
#
@@ -96,10 +100,11 @@ module YAML
#
# Write a text block with the current indent
#
- def indent_text( text, mod = nil )
+ def indent_text( text, mod, first_line = true )
return "" if text.to_s.empty?
spacing = indent( mod )
- return "\n" + text.gsub( /^([^\n])/, "#{spacing}\\1" )
+ text = text.gsub( /\A([^\n])/, "#{ spacing }\\1" ) if first_line
+ return text.gsub( /\n^([^\n])/, "\n#{spacing}\\1" )
end
#
@@ -127,7 +132,7 @@ module YAML
# Folding paragraphs within a column
#
def fold( value )
- value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]))|$)/ ) do |s|
+ value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do |s|
$1 || $2 + ( $3 || "\n" )
end
end