Skip to content

Commit

Permalink
[txt2folia] Prevent adding empty text content (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Sep 10, 2020
1 parent 27e6935 commit 5e069de
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions foliatools/txt2folia.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#-*- coding:utf-8 -*-

#---------------------------------------------------------------
# TEI to FoLiA Converter
# Text to FoLiA Converter
# by Maarten van Gompel
# Centre for Language Studies
# Radboud University Nijmegen
Expand Down Expand Up @@ -60,7 +60,11 @@ def convert(filename, **kwargs):
else:
if not line.strip():
#empty line, add buffer
body.append(folia.Paragraph, folia.TextContent(doc,*buffer))
try:
body.append(folia.Paragraph, folia.TextContent(doc,*buffer))
except ValueError:
#text is probably empty and could not be added (may have contained only control characters which were stripped autoamtically by the library)
pass
buffer = []
else:
buffer.append(line.strip())
Expand Down Expand Up @@ -98,7 +102,7 @@ def main():
print(doc.xmlstring())
else:
filename = os.path.basename(filename)
if filename[-4:] == '.xml':
if filename[-4:] in ('.xml','.txt'):
filename = filename[:-4] + '.folia.xml'
else:
filename += '.folia.xml'
Expand Down

0 comments on commit 5e069de

Please sign in to comment.