| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Yamlet.Internal.Render
Description
Rendering of the syntax tree.
This module is intended for internal use only, and may change without warning in subsequent releases.
Synopsis
- data RenderOptions = RenderOptions {
- forceBlock :: !Bool
- defaultRenderOptions :: RenderOptions
- renderSyntax :: RenderOptions -> [Document] -> Text
Documentation
data RenderOptions Source #
The options of renderSyntax.
Constructors
| RenderOptions | |
Fields
| |
Instances
| Generic RenderOptions Source # | |||||
Defined in Yamlet.Internal.Render Associated Types
| |||||
| Show RenderOptions Source # | |||||
Defined in Yamlet.Internal.Render Methods showsPrec :: Int -> RenderOptions -> ShowS show :: RenderOptions -> String showList :: [RenderOptions] -> ShowS | |||||
| Eq RenderOptions Source # | |||||
Defined in Yamlet.Internal.Render | |||||
| type Rep RenderOptions Source # | |||||
Defined in Yamlet.Internal.Render type Rep RenderOptions = D1 ('MetaData "RenderOptions" "Yamlet.Internal.Render" "yamlet-1.0.0.1-2nRkbEnNUrLFBALTocq2AS" 'False) (C1 ('MetaCons "RenderOptions" 'PrefixI 'True) (S1 ('MetaSel ('Just "forceBlock") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))) | |||||
defaultRenderOptions :: RenderOptions Source #
Keep the collection styles of the tree.
renderSyntax :: RenderOptions -> [Document] -> Text Source #
Render documents with their comments and empty lines.
The output differs from the tree where YAML cannot hold it:
- A
---marker is on a line of its own, with at most a comment after it. - A scalar keeps its style if the style can hold its text, otherwise it gets quotes. A block scalar that is a key or an entry of a flow collection gets double quotes. A block scalar at the root gets quotes in a few more cases, e.g. if its text starts with a space.
- The empty lines from the comments right after a block scalar with the
+indicator go away, because they would become part of the scalar. - A flow collection with comments inside becomes a block collection, so that every comment has a line.
- A flow collection without comments is on one line, apart from the line breaks of its multi-line scalars, so the empty lines between its entries go away.
- A key of more than 1024 characters in a flow mapping becomes an explicit
key, e.g.
{? key : value}, because YAML 1.1 parsers reject a longer implicit key there too. - A comment that has no place at its node moves to a place that has one, e.g. the lines above the value of a key go above the key if the value is on the line of the key.
- In the text of a comment, a character that YAML does not allow becomes
U+FFFD, and the white space at the end goes away. A line break starts a
new comment in a
CommentLine, and becomes a space in an inline comment. - An anchor name with a character that YAML does not allow in it, e.g. a
space, or that YAML 1.1 parsers read as the end of the name, e.g.
:or a line separator, becomes a new name in the anchor and in its aliases. Names that only some parsers reject stay, e.g.é, which libyaml rejects. - A version that the parser does not support, e.g. 2.0, has no
%YAMLdirective.
With forceBlock, the flow collections become block
collections:
>>>:{case parseDocumentsText "a: [1, {b: 2}]\n" of Left err -> putStrLn (prettyError "input.yaml" err) Right docs -> T.putStr (renderSyntax defaultRenderOptions {forceBlock = True} docs) :} a: - 1 - b: 2