diff --git a/testdata/example-in-breaklines.ttml b/testdata/example-in-breaklines.ttml
new file mode 100644
index 0000000..47de468
--- /dev/null
+++ b/testdata/example-in-breaklines.ttml
@@ -0,0 +1,24 @@
+
+
+
+
+
+ First line
+ Third line
+ Fifth line
+
+ Seventh line
+
+ First line
+
+ Third lineFourth line
+
+ Fifth line
+
+ Seventh line
+
+Second line
+
Fourth line
+
+ Sixth middle line
+
Eighth middle line
+
+ Second line
+
+ Sixth
+ middle
+ line
+
+ Eighth
+ middle
+ line
+
" + ts.Items + "
")), holdingToken: nil} +} + // TTMLInItem represents an input TTML item type TTMLInItem struct { Style string `xml:"style,attr,omitempty"` @@ -380,7 +412,7 @@ func ReadFromTTML(i io.Reader) (o *Subtitles, err error) { // Unmarshal items var items = TTMLInItems{} - if err = xml.Unmarshal([]byte(""+ts.Items+""), &items); err != nil { + if err = newTTMLXmlDecoder(ts).Decode(&items); err != nil { err = fmt.Errorf("astisub: unmarshaling items failed: %w", err) return } diff --git a/ttml_test.go b/ttml_test.go index 990c821..bba9e36 100644 --- a/ttml_test.go +++ b/ttml_test.go @@ -2,10 +2,12 @@ package astisub_test import ( "bytes" - "github.com/asticode/go-astikit" "io/ioutil" + "strings" "testing" + "github.com/asticode/go-astikit" + "github.com/asticode/go-astisub" "github.com/stretchr/testify/assert" ) @@ -50,3 +52,19 @@ func TestTTML(t *testing.T) { assert.NoError(t, err) assert.Equal(t, string(c), w.String()) } + +func TestTTMLBreakLines(t *testing.T) { + // Open + s, err := astisub.OpenFile("./testdata/example-in-breaklines.ttml") + assert.NoError(t, err) + + // Write + w := &bytes.Buffer{} + err = s.WriteToTTML(w) + assert.NoError(t, err) + + c, err := ioutil.ReadFile("./testdata/example-out-breaklines.ttml") + assert.NoError(t, err) + + assert.Equal(t, strings.TrimSpace(string(c)), strings.TrimSpace(w.String())) +}