@@ 15,7 15,8 @@ import Data.List (elemIndex)
import SpeechStyle
styleToSSML :: StyleTree SpeechStyle -> Element
-styleToSSML = Element "{http://www.w3.org/2001/10/synthesis}speak" M.empty . collapseBreaks' . styleToNodes
+styleToSSML = Element "{http://www.w3.org/2001/10/synthesis}speak" M.empty .
+ collapseBreaks' . floatBreaks' . styleToNodes
styleToNodes :: StyleTree SpeechStyle -> [Node]
styleToNodes = Prelude.map style . postorder styleToSSML'
@@ 91,6 92,17 @@ pitch2txt (Absolute (Unit' unit n)) = Txt.pack (show n) `Txt.append` unit
pitch2txt (Relative n) = unit2txt n
-- <break> collapse
+floatBreaks :: Element -> [Node]
+floatBreaks el@(Element _ _ childs)
+ | break@(NodeElement (Element "break" _ _)):nodes <- floatBreaks' childs =
+ break : floatBreaks el{elementNodes = nodes}
+ | break@(NodeElement (Element "break" _ _)):nodes <- reverse $ floatBreaks' childs =
+ floatBreaks el{elementNodes = reverse nodes} ++ [break]
+ | otherwise = [NodeElement el]
+floatBreaks' (NodeElement el:nodes) = floatBreaks el ++ floatBreaks' nodes
+floatBreaks' (node:nodes) = node : floatBreaks' nodes
+floatBreaks' [] = []
+
collapseBreaks :: Element -> Element
collapseBreaks (Element name attrs elChildren) =
Element name attrs $ collapseBreaks' elChildren