Skip to content

Commit

Permalink
Fix in maintaining leading spaces (+added test) (proycon/folia#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Mar 24, 2021
1 parent 66eb17c commit 3b093f6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion folia-repo
2 changes: 1 addition & 1 deletion folia/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ def text(self, cls='current', retaintokenisation=False, previousdelimiter="",str
if j > 0 and s2 and len(s) != l:
#insert spaces between lines that used to be newline separated
s += " "
elif j == 0 and s2 and line and line[0] in " \t" and not self.preservespace:
elif s2 and line and line[0] in " \t" and not self.preservespace:
#we have leading indentation we may need to collapse or ignore entirely
#we can't be sure yet what to do so we add a temporary placeholder \0
#this will later be handled in postprocess_spaces() (converts to a space only if no space preceeds it)
Expand Down
3 changes: 3 additions & 0 deletions folia/tests/maintest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4504,6 +4504,9 @@ def test013_nospace_feat(self):
"""Whitespace - No space despite t-hbr, markup and features"""
self.assertEqual( self.doc['test.p.13'].text() , "Es entspricht einerseits nicht den Erwartungen derjenigen, welche in betreff der Lage der Landarbeiter nur solche" )

def test014_leadingspace(self):
"""Whitespace - Maintain leading space"""
self.assertEqual( self.doc['test.p.14'].text() , "Terwijl hij den gemiddelden prijs van een karaat geslepen op £ 8 stelde, den prijs van een steen van 2 karaat op 22 X 8 = £ 32" )

with open(os.path.join(FOLIAPATH, 'examples/full-legacy.1.5.folia.xml'), 'r',encoding='utf-8') as foliaexample_f:
LEGACYEXAMPLE = foliaexample_f.read()
Expand Down

0 comments on commit 3b093f6

Please sign in to comment.