@@ -5,7 +5,9 @@ use crate::codec::Codec;
55use crate :: data:: Data ;
66use crate :: error:: ConvertError ;
77use crate :: format:: Format ;
8- use crate :: formats:: { CsvCodec , HttpFormCodec , JsonCodec , ProtobufCodec , TextCodec , XmlCodec } ;
8+ use crate :: formats:: {
9+ CsvCodec , HtmlCodec , HttpFormCodec , JsonCodec , ProtobufCodec , TextCodec , XmlCodec ,
10+ } ;
911use crate :: schema:: { DecodeContext , EncodeContext , JsonSchema } ;
1012use crate :: transform:: { data_into_markup, data_to_text, markup_into_data, markup_to_text} ;
1113use crate :: validation:: validate_json_schema;
@@ -24,6 +26,7 @@ impl Engine {
2426 let mut engine = Self :: new ( ) ;
2527 engine. register ( JsonCodec ) ;
2628 engine. register ( XmlCodec ) ;
29+ engine. register ( HtmlCodec ) ;
2730 engine. register ( TextCodec ) ;
2831 engine. register ( CsvCodec ) ;
2932 engine. register ( HttpFormCodec ) ;
@@ -180,6 +183,21 @@ mod tests {
180183 Ok ( ( ) )
181184 }
182185
186+ #[ test]
187+ fn json_converts_to_html_markup ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
188+ let engine = Engine :: with_default_codecs ( ) ;
189+ let html = engine. convert (
190+ br#"{"article":{"h1":"Hello","p":"World"}}"# ,
191+ Format :: Json ,
192+ Format :: Html ,
193+ & DecodeContext ,
194+ & EncodeContext :: default ( ) ,
195+ ) ?;
196+
197+ assert_eq ! ( html, b"<article><h1>Hello</h1><p>World</p></article>" ) ;
198+ Ok ( ( ) )
199+ }
200+
183201 #[ test]
184202 fn codecs_pretty_print_structured_output_when_requested ( )
185203 -> Result < ( ) , Box < dyn std:: error:: Error > > {
0 commit comments