Commits

Anonymous committed 3fa2f69

Working on enumerations

  • Participants
  • Parent commits ffe3a0e

Comments (0)

Files changed (1)

             
         _list = _newlist        
         # LIST
-        _list = self.group_type( _list, tag = 'list', clean= True,groupchildren=True)
+        #_list = self.group_type( _list, tag = 'list', clean= True)
+        _list = self.group_children( _list, tag = 'list', clean= True)
+        _newlist = []
+        for _i in _list:
+            if _i.__contains__('list'):
+                _tmp = self.clean( _i['list'], tags = ['list'])
+                _tmp1 = _i.copy()
+                _tmp1['list'] = _tmp
+                _newlist.append( _tmp1)
+            else:
+                _newlist.append( _i)
+        _list = _newlist
         for _i in _list:
             print _i
         _list = self.process_enumeration(_list)
                         #_list = _list + [ (_n, _tmp )]
                 _list = _list + [ (_n, _tmp) ]
         return _list
-    
+    def group_recursively(self, _list, tag = 'list'):
+        """Groups recursively up to making dissapear the tag
+        """
+        
+        pass
+
+    def has_tag(self):
+        pass
+
+    def group_children( self,
+                        _list, 
+                        tag = 'list',
+                        clean = False ):
+        """Groups one tag and all its children.
+        """
+        _newlist = []
+        _tmp = []
+        _flag = False
+        _n = 0
+        for _i in _list:
+            #_isTag = False
+            try:
+                if not _flag and self.types[ _i['child'].tag ] == tag:
+                    #_isTag = True
+                    _flag = True
+                    _n = _i['nesting']
+            except:
+                pass
+            
+            #if not _flag and _isTag:
+            #print _n, _i['nesting']
+            if _flag and _i['nesting'] > _n:
+                _tmp.append(_i ) 
+            else:
+                if _tmp != []:
+                    _newlist.append({tag : _tmp, 'nesting' : _n})
+                    _tmp = []
+                    _flag = False 
+                    _n = 0
+                _newlist.append(_i)
+        if _flag and _tmp!=[]:
+            _newlist.append({tag : _tmp, 'nesting' : _n})
+        return _newlist       
 
     def group_type( self,
                     _list, 
                     tag = 'note', 
-                    clean = False,
-                    groupchildren = False):
-        _pairs = self.extract_children(_list, tag, groupchildren)
+                    clean = False ):
+        _pairs = self.extract_children(_list, tag )
         if tag == 'list':
             print '    PAIRS: ',_pairs
         # Extract _list
         _newlist += _list[_oldidx:]
         return _newlist
 
-    def extract_children( self, _list, tag = 'note', groupchildren = False):
+    def extract_children( self, _list, tag = 'note'):
         _newlist = []
         _limits = []
         _flag = False
             _item = _list[_i]
             try:
                 if self.types[ _item['child'].tag ] == tag:
-                    _test = groupchildren and _item['nesting']< _nesting
-                    if not _test:
-                        if _flag:
-                            _limits.append(_i)
-                            _newlist.append( _limits)
-                        _flag = True
-                        _nesting = _item['nesting']+1
-                        _limits = [_i]                    
-                        _tmp = _item
+                    #_test = groupchildren and _item['nesting']< _nesting
+                    #if not _test:
+                    if _flag:
+                        _limits.append(_i)
+                        _newlist.append( _limits)
+                    _flag = True
+                    _nesting = _item['nesting']+1
+                    _limits = [_i]                    
+                    _tmp = _item
                     #if tag == 'list-item':
                     #   print '== OK ==', _limits
                     #   print _item['nesting']