@@ -33,6 +33,8 @@ module Text.Libyaml
3333 , defaultFormatOptions
3434 , setWidth
3535 , setCollectionTagRendering
36+ , setPlainTagRendering
37+ , setQuotedTagRendering
3638 , renderNone
3739 , renderAll
3840 , renderUriTags
@@ -469,13 +471,14 @@ toEventRaw opts e f = allocaBytes eventSize $ \er -> do
469471 len' = fromIntegral len :: CInt
470472 let thetag' = tagToString thetag
471473 withCString thetag' $ \tag' -> do
472− let (pi, style) =
473− case style0 of
474− PlainNoTag -> (1, Plain)
475− x -> (0, x)
474+ let pi0 = implicitPlain e
475+ qi = implicitQuoted e
476+ (pi, style) =
477+ case style0 of
478+ PlainNoTag -> (1, Plain)
479+ x -> (pi0, x)
476480 style' = toEnum $ fromEnum style
477481 tagP = castPtr tag'
478− qi = if null thetag' then 1 else 0
479482 case anchor of
480483 Nothing ->
481484 c_yaml_scalar_event_initialize
@@ -506,7 +509,7 @@ toEventRaw opts e f = allocaBytes eventSize $ \er -> do
506509 er
507510 nullPtr
508511 tagP
509− (implicit e)
512+ (implicitColl e)
510513 (toEnum $ fromEnum style)
511514 EventSequenceStart tag style (Just anchor) ->
512515 withCString (tagToString tag) $ \tag' -> do
@@ -517,7 +520,7 @@ toEventRaw opts e f = allocaBytes eventSize $ \er -> do
517520 er
518521 anchorP
519522 tagP
520− (implicit e)
523+ (implicitColl e)
521524 (toEnum $ fromEnum style)
522525 EventSequenceEnd ->
523526 c_yaml_sequence_end_event_initialize er
@@ -528,7 +531,7 @@ toEventRaw opts e f = allocaBytes eventSize $ \er -> do
528531 er
529532 nullPtr
530533 tagP
531− (implicit e)
534+ (implicitColl e)
532535 (toEnum $ fromEnum style)
533536 EventMappingStart tag style (Just anchor) ->
534537 withCString (tagToString tag) $ \tag' -> do
@@ -539,7 +542,7 @@ toEventRaw opts e f = allocaBytes eventSize $ \er -> do
539542 er
540543 anchorP
541544 tagP
542− (implicit e)
545+ (implicitColl e)
543546 (toEnum $ fromEnum style)
544547 EventMappingEnd ->
545548 c_yaml_mapping_end_event_initialize er
@@ -552,9 +555,17 @@ toEventRaw opts e f = allocaBytes eventSize $ \er -> do
552555 unless (ret == 1) $ throwIO $ ToEventRawException ret
553556 f er
554557 where
555− implicit (EventSequenceStart NoTag _ _) = 1
556− implicit (EventMappingStart NoTag _ _) = 1
557− implicit e = toEnum $ fromEnum $ formatOptionsRenderCollectionTags opts e
558+ implicitColl (EventMappingStart NoTag _ _) = 1
559+ implicitColl (EventSequenceStart NoTag _ _) = 1
560+ implicitColl (EventMappingStart (UriTag "") _ _) = 1
561+ implicitColl (EventSequenceStart (UriTag "") _ _) = 1
562+ implicitColl evt = toEnum $ fromEnum $ formatOptionsRenderCollectionTags opts evt
563+ implicitPlain (EventScalar _ NoTag _ _) = 1
564+ implicitPlain (EventScalar _ (UriTag "") _ _) = 1
565+ implicitPlain evt = toEnum $ fromEnum $ formatOptionsRenderPlainScalarTags opts evt
566+ implicitQuoted (EventScalar _ NoTag _ _) = 1
567+ implicitQuoted (EventScalar _ (UriTag "") _ _) = 1
568+ implicitQuoted evt = toEnum $ fromEnum $ formatOptionsRenderQuotedScalarTags opts evt
558569
559570newtype ToEventRawException = ToEventRawException CInt
560571 deriving (Show, Typeable)
@@ -686,7 +697,7 @@ renderNone :: Event -> TagRender
686697renderNone _ = Implicit
687698
688699-- | A value for 'formatOptionsRenderCollectionTags' that renders all
689−-- tags.
700+-- tags (except 'NoTag' and 'PlainNoTag' for flow scalars).
690701--
691702-- @since 0.11.1.0
692703renderAll :: Event -> TagRender
@@ -708,6 +719,8 @@ renderUriTags _ = Implicit
708719data FormatOptions = FormatOptions
709720 { formatOptionsWidth :: Maybe Int
710721 , formatOptionsRenderCollectionTags :: Event -> TagRender
722+ , formatOptionsRenderPlainScalarTags :: Event -> TagRender
723+ , formatOptionsRenderQuotedScalarTags :: Event -> TagRender
711724 }
712725
713726-- |
@@ -716,6 +729,8 @@ defaultFormatOptions :: FormatOptions
716729defaultFormatOptions = FormatOptions
717730 { formatOptionsWidth = Just 80 -- by default the width is set to 0 in the C code, which gets turned into 80 in yaml_emitter_emit_stream_start
718731 , formatOptionsRenderCollectionTags = renderNone
732+ , formatOptionsRenderPlainScalarTags = renderAll
733+ , formatOptionsRenderQuotedScalarTags = renderAll
719734 }
720735
721736-- | Set the maximum number of columns in the YAML output, or 'Nothing' for infinite. By default, the limit is 80 characters.
@@ -724,12 +739,24 @@ defaultFormatOptions = FormatOptions
724739setWidth :: Maybe Int -> FormatOptions -> FormatOptions
725740setWidth w opts = opts { formatOptionsWidth = w }
726741
727−-- | Control when and whether collection tags are rendered to output.
742+-- | Control when and whether tags on collections are rendered to output.
728743--
729744-- @since 0.11.1.0
730745setCollectionTagRendering :: (Event -> TagRender) -> FormatOptions -> FormatOptions
731746setCollectionTagRendering f opts = opts { formatOptionsRenderCollectionTags = f }
732747
748+-- | Control when and whether tags on plain scalars are rendered to output.
749+--
750+-- @since 0.11.1.0
751+setPlainTagRendering :: (Event -> TagRender) -> FormatOptions -> FormatOptions
752+setPlainTagRendering f opts = opts { formatOptionsRenderPlainScalarTags = f }
753+
754+-- | Control when and whether tags on quoted scalars are rendered to output.
755+--
756+-- @since 0.11.1.0
757+setQuotedTagRendering :: (Event -> TagRender) -> FormatOptions -> FormatOptions
758+setQuotedTagRendering f opts = opts { formatOptionsRenderQuotedScalarTags = f }
759+
733760encode :: MonadResource m => ConduitM Event o m ByteString
734761encode = encodeWith defaultFormatOptions
735762