-- | A literal string.
text :: String -> Doc
text = Doc . toChunks
  where toChunks :: String -> DList D
        toChunks [] = mempty
        toChunks s = case break (=='\n') s of
                          ([], _:ys) -> NewLine `cons` toChunks ys
                          (xs, _:ys) -> Text (realLength xs) xs `cons`
                                            NewLine `cons` toChunks ys
                          (xs, [])      -> singleton $ Text (realLength xs) xs

-- | A character.
text :: String -> Doc
text = Doc . toChunks
  where toChunks :: String -> DList D
        toChunks [] = mempty
        toChunks s = case break (=='\n') s of
                          ([], _:ys) -> NewLine `cons` toChunks ys
                          (xs, _:ys) -> Text (realLength xs) xs `cons`
                                            NewLine `cons` toChunks ys
                          (xs, [])      -> singleton $ Text (realLength xs) xs

-- | A character.
text = Doc . toChunks
  where toChunks :: String -> DList D
        toChunks [] = mempty
        toChunks s = case break (=='\n') s of
                          ([], _:ys) -> NewLine `cons` toChunks ys
                          (xs, _:ys) -> Text (realLength xs) xs `cons`
                                            NewLine `cons` toChunks ys
                          (xs, [])      -> singleton $ Text (realLength xs) xs

-- | A character.