@@ -46,29 +46,59 @@ public class ImageBlock(DirectiveBlockParser parser, Dictionary<string, string>
4646 /// </summary>
4747 public string ? Target { get ; set ; }
4848
49- /// <summary>
50- /// A space-separated list of CSS classes to add to the image.
51- /// </summary>
52- public string ? Classes { get ; protected set ; }
53-
5449 /// <summary>
5550 /// A reference target for the admonition (see cross-referencing).
5651 /// </summary>
57- public string ? CrossReferenceName { get ; private set ; }
52+ public string ? Label { get ; private set ; }
53+
54+ public string ? ImageUrl { get ; private set ; }
55+
56+ public bool Found { get ; private set ; }
5857
59- public string ImageUrl { get ; private set ; } = default ! ;
6058
6159 public override void FinalizeAndValidate ( ParserContext context )
6260 {
63- ImageUrl = Arguments ?? string . Empty ; //todo validate
64- Classes = Properties . GetValueOrDefault ( "class" ) ;
65- CrossReferenceName = Properties . GetValueOrDefault ( "name" ) ;
66- Alt = Properties . GetValueOrDefault ( "alt" ) ;
67- Height = Properties . GetValueOrDefault ( "height" ) ;
68- Width = Properties . GetValueOrDefault ( "width" ) ;
69- Scale = Properties . GetValueOrDefault ( "scale" ) ;
70- Align = Properties . GetValueOrDefault ( "align" ) ;
71- Target = Properties . GetValueOrDefault ( "target" ) ;
61+ Label = Prop ( "label" , "name" ) ;
62+ Alt = Prop ( "alt" ) ;
63+ Align = Prop ( "align" ) ;
64+
65+ Height = Prop ( "height" , "h" ) ;
66+ Width = Prop ( "width" , "w" ) ;
67+
68+ Scale = Prop ( "scale" ) ;
69+ Target = Prop ( "target" ) ;
70+
71+ ExtractImageUrl ( context ) ;
72+
73+ }
74+
75+ private void ExtractImageUrl ( ParserContext context )
76+ {
77+ var imageUrl = Arguments ;
78+ if ( string . IsNullOrWhiteSpace ( imageUrl ) )
79+ {
80+ EmitError ( context , $ "{ Directive } requires an argument.") ;
81+ return ;
82+ }
83+
84+ if ( Uri . TryCreate ( imageUrl , UriKind . Absolute , out var uri ) && uri . Scheme . StartsWith ( "http" ) )
85+ {
86+ EmitWarning ( context , $ "{ Directive } is using an external URI: { uri } ") ;
87+ Found = true ;
88+ ImageUrl = imageUrl ;
89+ return ;
90+ }
91+
92+ var includeFrom = context . Path . Directory ! . FullName ;
93+ if ( imageUrl . StartsWith ( '/' ) )
94+ includeFrom = context . Parser . SourcePath . FullName ;
95+
96+ ImageUrl = imageUrl ;
97+ var imagePath = Path . Combine ( includeFrom , imageUrl . TrimStart ( '/' ) ) ;
98+ if ( context . Build . ReadFileSystem . File . Exists ( imageUrl ) )
99+ Found = true ;
100+ else
101+ EmitError ( context , $ "`{ imageUrl } ` does not exist. resolved to `{ imagePath } ") ;
72102 }
73103}
74104
0 commit comments