Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/ass/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ def parse_file(cls, f):
" usually '%s'" % cls.PREFERRED_ENCODING.name)

line = line.strip()
if not line or line.startswith(';'):
if not line:
continue

if line.startswith(';'):
# ";" comments only permitted in Script Info section, ignore otherwise
if section == doc.sections.get("Script Info"):
section.add_comment(line[1:])
continue

if line.startswith('[') and line.endswith(']'):
Expand Down
12 changes: 12 additions & 0 deletions src/ass/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def add_line(self, field_name, field):
def dump(self):
yield "[{}]".format(self.name)

# Comments are customarily at the beginning
if hasattr(self, "comments"):
for c in self.comments:
yield ";{}".format(c)

for k, v in self._fields.items():
yield "{}: {}".format(k, _Field.dump(v))

Expand Down Expand Up @@ -149,3 +154,10 @@ class ScriptInfoSection(FieldSection):
"WrapStyle": _Field("WrapStyle", int, default=0),
"ScaledBorderAndShadow": _Field("ScaledBorderAndShadow", str, default="yes")
}

def add_comment(self, comment):
self.comments.append(comment)

def __init__(self, name, fields=None):
super().__init__(name, fields=fields)
self.comments = []