@@ -61,7 +61,7 @@ def non_zero(self) -> Wiki:
61
61
fields .append (Field (key = f .key , value = v ))
62
62
continue
63
63
64
- return Wiki (type = self .type , fields = tuple (fields ))
64
+ return Wiki (type = self .type , fields = tuple (fields ), _eol = self . _eol )
65
65
66
66
def get (self , key : str ) -> str | list [Item ] | None :
67
67
for f in self .fields :
@@ -100,11 +100,11 @@ def __set(self, field: Field) -> Wiki:
100
100
if not found :
101
101
fields .append (field )
102
102
103
- return Wiki (type = self .type , fields = tuple (fields ))
103
+ return Wiki (type = self .type , fields = tuple (fields ), _eol = self . _eol )
104
104
105
105
def remove (self , key : str ) -> Wiki :
106
106
fields = tuple (f for f in self .fields if f .key != key )
107
- return Wiki (type = self .type , fields = fields )
107
+ return Wiki (type = self .type , fields = fields , _eol = self . _eol )
108
108
109
109
def semantics_equal (self , other : Wiki ) -> bool :
110
110
if self .type != other .type :
@@ -197,11 +197,11 @@ def try_parse(s: str) -> Wiki:
197
197
198
198
def parse (s : str ) -> Wiki :
199
199
crlf = s .count ("\r \n " )
200
- lf = s .count ("\n " )
201
- if crlf == 0 or lf == 0 or lf > crlf :
202
- eol = "\n "
203
- else :
200
+ lf = s .count ("\n " ) - crlf
201
+ if crlf >= lf :
204
202
eol = "\r \n "
203
+ else :
204
+ eol = "\n "
205
205
206
206
s = s .replace ("\r \n " , "\n " )
207
207
s , line_offset = _process_input (s )
@@ -371,11 +371,12 @@ def __render(w: Wiki) -> Generator[str, None, None]:
371
371
if isinstance (field .value , str ):
372
372
yield f"|{ field .key } = { field .value } "
373
373
elif isinstance (field .value , list ):
374
- yield f"|{ field .key } = {{"
374
+ yield f"|{ field .key } ={{"
375
375
yield from __render_items (field .value )
376
376
yield "}"
377
377
elif field .value is None :
378
- yield f"|{ field .key } ="
378
+ # default editor will add a space
379
+ yield f"|{ field .key } = "
379
380
else :
380
381
raise TypeError ("type not support" , type (field .value ))
381
382
0 commit comments