88#[ allow( clippy:: return_self_not_must_use) ]
99#[ derive( Clone , Debug ) ]
1010pub struct Configuration {
11- /// The XML namespace to use when scanning for ESI tags. Defaults to `esi` .
12- pub namespace : String ,
11+ // Define the tag names that the processor will operate on .
12+ pub tag_names : TagNames ,
1313 /// For working with non-HTML ESI templates, e.g. JSON files, this option allows you to disable the unescaping of URLs
1414 pub is_escaped_content : bool ,
1515}
1616
1717impl Default for Configuration {
1818 fn default ( ) -> Self {
1919 Self {
20- namespace : String :: from ( "esi" ) ,
20+ tag_names : Default :: default ( ) ,
2121 is_escaped_content : true ,
2222 }
2323 }
@@ -28,7 +28,12 @@ impl Configuration {
2828 ///
2929 /// For example, setting this to `test` would cause the processor to only match tags like `<test:include>`.
3030 pub fn with_namespace ( mut self , namespace : impl Into < String > ) -> Self {
31- self . namespace = namespace. into ( ) ;
31+ self . tag_names = TagNames :: from_namespace_with_defaults ( & namespace. into ( ) ) ;
32+ self
33+ }
34+ /// Sets the tag names that the processor will operate on.
35+ pub fn with_tag_names ( mut self , tag_names : TagNames ) -> Self {
36+ self . tag_names = tag_names;
3237 self
3338 }
3439 /// For working with non-HTML ESI templates, eg JSON files, allows to disable URLs unescaping
@@ -37,3 +42,34 @@ impl Configuration {
3742 self
3843 }
3944}
45+
46+ /// Defines the HTML tag names that the processor will operate on.
47+ #[ derive( Clone , Debug ) ]
48+ pub struct TagNames {
49+ pub include : Vec < u8 > ,
50+ pub comment : Vec < u8 > ,
51+ pub remove : Vec < u8 > ,
52+ pub r#try : Vec < u8 > ,
53+ pub attempt : Vec < u8 > ,
54+ pub except : Vec < u8 > ,
55+ }
56+
57+ impl TagNames {
58+ /// Returns tag names as defined within the ESI specification within the given namespace.
59+ pub fn from_namespace_with_defaults ( namespace : & str ) -> Self {
60+ Self {
61+ include : format ! ( "{namespace}:include" , ) . into_bytes ( ) ,
62+ comment : format ! ( "{namespace}:comment" , ) . into_bytes ( ) ,
63+ remove : format ! ( "{namespace}:remove" , ) . into_bytes ( ) ,
64+ r#try : format ! ( "{namespace}:try" , ) . into_bytes ( ) ,
65+ attempt : format ! ( "{namespace}:attempt" , ) . into_bytes ( ) ,
66+ except : format ! ( "{namespace}:except" , ) . into_bytes ( ) ,
67+ }
68+ }
69+ }
70+
71+ impl Default for TagNames {
72+ fn default ( ) -> Self {
73+ Self :: from_namespace_with_defaults ( "esi" )
74+ }
75+ }
0 commit comments