Skip to content

Commit

Permalink
Fixing writing of an empty head (#189) (#202)
Browse files Browse the repository at this point in the history
Closes #189

* Fixing writing of an empty head (#189)
* Do not emit styling element if initial element errors out
  • Loading branch information
BobBrownConsulting authored Dec 22, 2020
1 parent befa19e commit 6c6a150
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/python/ttconv/imsc/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,20 @@ def from_model(
`ctx` contains state information used in the process.
'''

head_element = et.Element(HeadElement.qn)
head_element = None

styling_element = StylingElement.from_model(ctx, model_doc)

if styling_element is not None:
if head_element is None:
head_element = et.Element(HeadElement.qn)
head_element.append(styling_element)

layout_element = LayoutElement.from_model(ctx, model_doc)

if layout_element is not None:
if head_element is None:
head_element = et.Element(HeadElement.qn)
head_element.append(layout_element)

return head_element
Expand Down Expand Up @@ -434,11 +438,13 @@ def from_model(
`ctx` contains state information used in the process.
'''

layout_element = et.Element(LayoutElement.qn)
layout_element = None

for r in model_doc.iter_regions():
region_element = RegionElement.from_model(ctx, r)
if region_element is not None:
if layout_element is None:
layout_element = et.Element(LayoutElement.qn)
layout_element.append(region_element)

return layout_element
Expand Down Expand Up @@ -527,9 +533,7 @@ def from_model(
styling_element = None

for style_prop, style_value in model_doc.iter_initial_values():
if styling_element is None:
styling_element = et.Element(StylingElement.qn)


imsc_style_prop = imsc_styles.StyleProperties.BY_MODEL_PROP.get(style_prop)

if imsc_style_prop is None:
Expand All @@ -538,6 +542,8 @@ def from_model(

initial_element = InitialElement.from_model(imsc_style_prop, style_value)
if initial_element is not None:
if styling_element is None:
styling_element = et.Element(StylingElement.qn)
styling_element.append(initial_element)

return styling_element
Expand Down

0 comments on commit 6c6a150

Please sign in to comment.