1+ using System ;
2+ using System . Runtime . CompilerServices ;
3+ using Contentstack . Utils . Enums ;
4+ using HtmlAgilityPack ;
5+
6+ [ assembly: InternalsVisibleTo ( "Contentstack.Utils.Tests" ) ]
7+ namespace Contentstack . Utils . Models
8+ {
9+ public struct Metadata
10+ {
11+ /// <summary>
12+ /// This will specify the type of Embedded object
13+ /// </summary>
14+ public EmbedItemType ItemType ;
15+
16+ /// <summary>
17+ /// This will specify the style type of Embedded object
18+ /// </summary>
19+ public StyleType StyleType ;
20+
21+ /// <summary>
22+ /// Uid of Embedded object
23+ /// </summary>
24+ public string ItemUid ;
25+
26+ /// <summary>
27+ /// Content type for the Embedded object
28+ /// </summary>
29+ public string ContentTypeUid ;
30+
31+ /// <summary>
32+ /// Text wrapped in embed tag
33+ /// </summary>
34+ public string Text ;
35+
36+ /// <summary>
37+ /// Attributes collection for embed tag
38+ /// </summary>
39+ public HtmlAttributeCollection attributes ;
40+
41+ /// <summary>
42+ /// Html string of embed tag
43+ /// </summary>
44+ internal string OuterHTML ;
45+
46+ public static implicit operator Metadata ( HtmlNode node )
47+ {
48+ StyleType styleType ;
49+ if ( node . Attributes [ "sys-style-type" ] == null || ! ( Enum . TryParse ( node . Attributes [ "sys-style-type" ] . Value , true , out styleType ) ) )
50+ {
51+ styleType = StyleType . Block ;
52+ }
53+
54+ EmbedItemType embedItemType ;
55+ if ( node . Attributes [ "type" ] == null || ! ( Enum . TryParse ( node . Attributes [ "type" ] . Value , true , out embedItemType ) ) )
56+ {
57+ embedItemType = EmbedItemType . Entry ;
58+ }
59+
60+ return new Metadata ( ) {
61+ Text = node . InnerText ?? "" ,
62+ OuterHTML = node . OuterHtml ?? "" ,
63+ StyleType = styleType ,
64+ ItemType = embedItemType ,
65+ ItemUid = node . Attributes [ "data-sys-entry-uid" ] != null ? node . Attributes [ "data-sys-entry-uid" ] . Value : ( node . Attributes [ "data-sys-asset-uid" ] != null ? node . Attributes [ "data-sys-asset-uid" ] . Value : "" ) ,
66+ ContentTypeUid = node . Attributes [ "data-sys-content-type-uid" ] != null ? node . Attributes [ "data-sys-content-type-uid" ] . Value : "" ,
67+ attributes = node . Attributes
68+ } ;
69+ }
70+ }
71+ }
0 commit comments