@@ -19,46 +19,50 @@ class RowSplitter(object):
1919 _comment_mark = '#'
2020 _empty_cell_escape = '${EMPTY}'
2121 _line_continuation = '...'
22+ _setting_table = 'setting'
23+ _tc_table = 'test case'
24+ _kw_table = 'keyword'
2225
23- def __init__ (self , cols = 8 , split_doc = True ):
26+ def __init__ (self , cols = 8 , split_multiline_doc = True ):
2427 self ._cols = cols
25- self ._split_doc = split_doc
28+ self ._split_multiline_doc = split_multiline_doc
2629
27- def split (self , row , indented_table = False ): # TODO: pass table type instead
30+ def split (self , row , table_type ):
2831 if not row :
2932 return self ._split_empty_row ()
30- indent = self ._get_indent (row , indented_table )
31- if self ._split_doc and self ._is_doc_row (row , indented_table ):
33+ indent = self ._get_indent (row , table_type )
34+ if self ._split_multiline_doc and self ._is_doc_row (row , table_type ):
3235 return self ._split_doc_row (row , indent )
3336 return self ._split_row (row , indent )
3437
3538 def _split_empty_row (self ):
3639 yield []
3740
38- def _is_doc_row (self , row , tc_or_kw_table ):
39- if tc_or_kw_table :
41+ def _get_indent (self , row , table_type ):
42+ indent = len (list (itertools .takewhile (lambda x : x == '' , row )))
43+ min_indent = 1 if table_type in [self ._tc_table , self ._kw_table ] else 0
44+ return max (indent , min_indent )
45+
46+ def _is_doc_row (self , row , table_type ):
47+ if table_type == self ._setting_table :
48+ return len (row ) > 1 and row [0 ] == 'Documentation'
49+ if table_type in [self ._tc_table , self ._kw_table ]:
4050 return len (row ) > 2 and row [1 ] == '[Documentation]'
41- return len ( row ) > 1 and row [ 0 ] == 'Documentation'
51+ return False
4252
4353 def _split_doc_row (self , row , indent ):
44- first , rest = self ._split_row_from_doc (row [indent + 1 ])
45- yield row [:indent + 1 ] + [first ]
54+ first , rest = self ._split_doc (row [indent + 1 ])
55+ yield row [:indent + 1 ] + [first ] + row [ indent + 2 :]
4656 while rest :
47- current , rest = self ._split_row_from_doc (rest )
57+ current , rest = self ._split_doc (rest )
4858 yield self ._indent ([self ._line_continuation , current ], indent )
4959
50- def _split_row_from_doc (self , doc ):
60+ def _split_doc (self , doc ):
5161 if '\\ n' not in doc :
5262 return doc , ''
53- first , rest = doc .split ('\\ n' , 1 )
54- if rest .startswith (' ' ):
55- rest = rest [1 :]
56- return first , rest
57-
58- def _get_indent (self , row , indented_table ):
59- indent = len (list (itertools .takewhile (lambda x : x == '' , row )))
60- min_indent = 1 if indented_table else 0
61- return max (indent , min_indent )
63+ if '\\ n ' in doc :
64+ doc = doc .replace ('\\ n ' , '\\ n' )
65+ return doc .split ('\\ n' , 1 )
6266
6367 def _split_row (self , row , indent ):
6468 while row :
0 commit comments