Changeset 304


Ignore:
Timestamp:
12/04/08 06:32:12 (6 years ago)
Author:
xi
Message:

Fixed a problem with emitting block scalars (thanks to Andrey Somov): no longer emit indentation spaces when they are not needed; emit the correct number of leading breaks for folded scalars; emit the '+' chomping indicator for a single break scalar.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pyyaml/trunk/lib/yaml/emitter.py

    r300 r304  
    10101010    def determine_block_hints(self, text): 
    10111011        hints = u'' 
    1012         if text and text[0] in u' \n\x85\u2028\u2029': 
    1013             hints += unicode(self.best_indent) 
    1014         tail = text[-2:] 
    1015         while len(tail) < 2: 
    1016             tail = u' '+tail 
    1017         if tail[-1] in u'\n\x85\u2028\u2029': 
    1018             if tail[-2] in u'\n\x85\u2028\u2029': 
     1012        if text: 
     1013            if text[0] in u' \n\x85\u2028\u2029': 
     1014                hints += unicode(self.best_indent) 
     1015            if text[-1] not in u'\n\x85\u2028\u2029': 
     1016                hints += u'-' 
     1017            elif len(text) == 1 or text[-2] in u'\n\x85\u2028\u2029': 
    10191018                hints += u'+' 
    1020         else: 
    1021             hints += u'-' 
    10221019        return hints 
    10231020 
     
    10251022        hints = self.determine_block_hints(text) 
    10261023        self.write_indicator(u'>'+hints, True) 
    1027         self.write_indent() 
    1028         leading_space = False 
     1024        self.write_line_break() 
     1025        leading_space = True 
    10291026        spaces = False 
    1030         breaks = False 
     1027        breaks = True 
    10311028        start = end = 0 
    10321029        while end <= len(text): 
     
    10761073        chomp = self.determine_block_hints(text) 
    10771074        self.write_indicator(u'|'+chomp, True) 
    1078         self.write_indent() 
    1079         breaks = False 
     1075        self.write_line_break() 
     1076        breaks = True 
    10801077        start = end = 0 
    10811078        while end <= len(text): 
Note: See TracChangeset for help on using the changeset viewer.