11//! Options for Astro codegen.
22//!
3- //! Some fields (such as `compact`, ` sourcemap`, CSS scoping) are accepted but
3+ //! Some fields (such as `sourcemap`, CSS scoping) are accepted but
44//! stubbed for API compatibility.
55
66/// Controls whether and how source maps are emitted.
@@ -25,6 +25,26 @@ impl SourcemapOption {
2525 }
2626}
2727
28+ /// Controls how whitespace is collapsed in the HTML output.
29+ ///
30+ /// - `Disabled` (default): no whitespace modification.
31+ /// - `Html`: HTML-aware whitespace collapsing, following the same rules as a browser
32+ /// (preserves significant whitespace, collapses runs of whitespace to a single
33+ /// space or newline, removes whitespace-only text nodes in insensitive contexts).
34+ /// Matches the Go compiler's `compact: true` behavior.
35+ /// - `Jsx`: removes all whitespace-only text nodes and strips leading/trailing
36+ /// whitespace from text content. Similar to how JSX transformers handle whitespace.
37+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Default ) ]
38+ pub enum CompactMode {
39+ /// No whitespace modification (default).
40+ #[ default]
41+ Disabled ,
42+ /// HTML-aware whitespace collapsing (Go compiler `compact: true` behavior).
43+ Html ,
44+ /// Strip all whitespace-only text nodes and leading/trailing whitespace.
45+ Jsx ,
46+ }
47+
2848/// Scoped style strategy for CSS scoping.
2949///
3050/// Determines how Astro scopes CSS selectors to components.
@@ -66,11 +86,12 @@ pub struct TransformOptions {
6686 /// Defaults to `"https://astro.build"`.
6787 pub astro_global_args : Option < String > ,
6888
69- /// Whether to collapse whitespace in the HTML output.
89+ /// Controls how whitespace is collapsed in the HTML output.
7090 ///
71- /// **Stub**: compact mode is not yet implemented; this field is accepted
72- /// for API compatibility.
73- pub compact : bool ,
91+ /// - `Disabled` (default): no whitespace modification.
92+ /// - `Html`: HTML-aware collapsing following browser whitespace rules.
93+ /// - `Jsx`: strip all whitespace-only text nodes and leading/trailing whitespace.
94+ pub compact : CompactMode ,
7495
7596 /// Enable scoped slot result handling.
7697 ///
@@ -149,7 +170,7 @@ impl Default for TransformOptions {
149170 internal_url : None ,
150171 sourcemap : SourcemapOption :: default ( ) ,
151172 astro_global_args : None ,
152- compact : false ,
173+ compact : CompactMode :: Disabled ,
153174 result_scoped_slot : false ,
154175 scoped_style_strategy : ScopedStyleStrategy :: default ( ) ,
155176 transitions_animation_url : None ,
@@ -226,9 +247,13 @@ impl TransformOptions {
226247 self
227248 }
228249
229- /// Enable or disable compact mode (stub).
250+ /// Set the compact whitespace collapsing mode.
251+ ///
252+ /// - `CompactMode::Disabled`: no whitespace modification (default).
253+ /// - `CompactMode::Html`: HTML-aware collapsing (Go compiler behavior).
254+ /// - `CompactMode::Jsx`: strip all whitespace-only text nodes.
230255 #[ must_use]
231- pub fn with_compact ( mut self , compact : bool ) -> Self {
256+ pub fn with_compact ( mut self , compact : CompactMode ) -> Self {
232257 self . compact = compact;
233258 self
234259 }
0 commit comments