Skip to content

Commit

Permalink
Improve skip of empty lines #28
Browse files Browse the repository at this point in the history
  • Loading branch information
glut23 committed Mar 27, 2020
1 parent 7d84c01 commit ee954c7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions webvtt/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,14 @@ def _compute_blocks(self, lines):
blocks = []

for index, line in enumerate(lines, start=1):
# clean up exstraneous whitespace
final_line = line.strip()

# Remove empty lines
if final_line:
if line:
if not blocks:
blocks.append(Block(index))
if not blocks[-1].lines:
if not line.strip():
continue
blocks[-1].line_number = index
blocks[-1].lines.append(final_line)
blocks[-1].lines.append(line)
else:
blocks.append(Block(index))

Expand All @@ -198,7 +196,7 @@ def _parse_cue_block(self, block):
'{} in line {}'.format(e, block.line_number + line_number))
else:
additional_blocks = self._compute_blocks(
['WEBVTT', '\n'] + block.lines[line_number:]
['WEBVTT', ''] + block.lines[line_number:]
)
break
elif line_number == 0:
Expand Down

0 comments on commit ee954c7

Please sign in to comment.