@@ -12,7 +12,6 @@ use crate::{
1212 write,
1313} ;
1414
15- // TODO: rename these to align with prettier
1615#[ derive( Debug , Default , Clone ) ]
1716pub struct FormatOptions {
1817 /// The indent style.
@@ -63,6 +62,9 @@ pub struct FormatOptions {
6362 /// - `"end"`: Places the operator at the end of the current line (default).
6463 pub experimental_operator_position : OperatorPosition ,
6564
65+ /// Enable formatting for embedded languages (e.g., CSS, SQL, GraphQL) within template literals. Defaults to "auto".
66+ pub embedded_language_formatting : EmbeddedLanguageFormatting ,
67+
6668 // TODO: `FormatOptions`? Split out as `TransformOptions`?
6769 /// Sort import statements. By default disabled.
6870 pub experimental_sort_imports : Option < SortImports > ,
@@ -86,6 +88,7 @@ impl FormatOptions {
8688 attribute_position : AttributePosition :: default ( ) ,
8789 expand : Expand :: default ( ) ,
8890 experimental_operator_position : OperatorPosition :: default ( ) ,
91+ embedded_language_formatting : EmbeddedLanguageFormatting :: default ( ) ,
8992 experimental_sort_imports : None ,
9093 }
9194 }
@@ -112,6 +115,7 @@ impl fmt::Display for FormatOptions {
112115 writeln ! ( f, "Attribute Position: {}" , self . attribute_position) ?;
113116 writeln ! ( f, "Expand lists: {}" , self . expand) ?;
114117 writeln ! ( f, "Experimental operator position: {}" , self . experimental_operator_position) ?;
118+ writeln ! ( f, "Embedded language formatting: {}" , self . embedded_language_formatting) ?;
115119 writeln ! ( f, "Experimental sort imports: {:?}" , self . experimental_sort_imports)
116120 }
117121}
@@ -914,6 +918,47 @@ impl fmt::Display for OperatorPosition {
914918 }
915919}
916920
921+ #[ derive( Clone , Copy , Debug , Default , Eq , Hash , PartialEq ) ]
922+ pub enum EmbeddedLanguageFormatting {
923+ /// Enable formatting for embedded languages.
924+ #[ default]
925+ Auto ,
926+ /// Disable formatting for embedded languages.
927+ Off ,
928+ }
929+
930+ impl EmbeddedLanguageFormatting {
931+ pub const fn is_auto ( self ) -> bool {
932+ matches ! ( self , Self :: Auto )
933+ }
934+
935+ pub const fn is_off ( self ) -> bool {
936+ matches ! ( self , Self :: Off )
937+ }
938+ }
939+
940+ impl FromStr for EmbeddedLanguageFormatting {
941+ type Err = & ' static str ;
942+
943+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
944+ match s {
945+ "auto" => Ok ( Self :: Auto ) ,
946+ "off" => Ok ( Self :: Off ) ,
947+ _ => Err ( "Value not supported for EmbeddedLanguageFormatting" ) ,
948+ }
949+ }
950+ }
951+
952+ impl fmt:: Display for EmbeddedLanguageFormatting {
953+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
954+ let s = match self {
955+ EmbeddedLanguageFormatting :: Auto => "Auto" ,
956+ EmbeddedLanguageFormatting :: Off => "Off" ,
957+ } ;
958+ f. write_str ( s)
959+ }
960+ }
961+
917962// ---
918963
919964#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
0 commit comments