@@ -112,23 +112,44 @@ def process_thymeleaf_syntax(self, content, template_name):
112112
113113 def replace_th_text (self , content ):
114114 """Replace th:text attributes with mock values."""
115- replacements = {
116- r'th:text="\$\{totalScore\}"' : f'>{ self .mock_data ["totalScore" ]} <' ,
117- r'th:text="\$\{sessioncounter\}"' : f'>{ self .mock_data ["sessioncounter" ]} <' ,
118- r'th:text="\$\{canaryCounter\}"' : f'>{ self .mock_data ["canaryCounter" ]} <' ,
119- r'th:text="\$\{lastCanaryToken\}"' : f'>{ self .mock_data ["lastCanaryToken" ]} <' ,
120- r'th:text="\$\{hintsEnabled\}"' : f'>{ self .mock_data ["hintsEnabled" ]} <' ,
121- r'th:text="\$\{reasonEnabled\}"' : f'>{ self .mock_data ["reasonEnabled" ]} <' ,
122- r'th:text="\$\{ctfModeEnabled\}"' : f'>{ self .mock_data ["ctfModeEnabled" ]} <' ,
123- r'th:text="\$\{spoilingEnabled\}"' : f'>{ self .mock_data ["spoilingEnabled" ]} <' ,
124- r'th:text="\$\{swaggerUIEnabled\}"' : f'>{ self .mock_data ["swaggerUIEnabled" ]} <' ,
125- r'th:text="\$\{springdocenabled\}"' : f'>{ self .mock_data ["springdocenabled" ]} <' ,
126- r'th:text="\$\{swaggerURI\}"' : f'>{ self .mock_data ["swaggerURI" ]} <' ,
127- r'th:text="\$\{#strings\.replace\(environment,\'_\',\' _\'\)\}"' : f'>{ self .mock_data ["environment" ]} <' ,
128- r'th:text="\'Total score: \'\+\$\{totalScore\}"' : f'>Total score: { self .mock_data ["totalScore" ]} <' ,
115+ # Handle th:text patterns with proper content replacement
116+ patterns = [
117+ (r'<span[^>]*th:text="\$\{totalScore\}"[^>]*>[^<]*</span>' , f'<span>{ self .mock_data ["totalScore" ]} </span>' ),
118+ (r'<span[^>]*th:text="\$\{sessioncounter\}"[^>]*>[^<]*</span>' , f'<span>{ self .mock_data ["sessioncounter" ]} </span>' ),
119+ (r'<span[^>]*th:text="\$\{canaryCounter\}"[^>]*>[^<]*</span>' , f'<span>{ self .mock_data ["canaryCounter" ]} </span>' ),
120+ (r'<span[^>]*th:text="\$\{lastCanaryToken\}"[^>]*>[^<]*</span>' , f'<span>{ self .mock_data ["lastCanaryToken" ]} </span>' ),
121+ (r'<span[^>]*th:text="\$\{hintsEnabled\}"[^>]*>[^<]*</span>' , f'<span>{ self .mock_data ["hintsEnabled" ]} </span>' ),
122+ (r'<span[^>]*th:text="\$\{reasonEnabled\}"[^>]*>[^<]*</span>' , f'<span>{ self .mock_data ["reasonEnabled" ]} </span>' ),
123+ (r'<span[^>]*th:text="\$\{ctfModeEnabled\}"[^>]*>[^<]*</span>' , f'<span>{ self .mock_data ["ctfModeEnabled" ]} </span>' ),
124+ (r'<span[^>]*th:text="\$\{spoilingEnabled\}"[^>]*>[^<]*</span>' , f'<span>{ self .mock_data ["spoilingEnabled" ]} </span>' ),
125+ (r'<span[^>]*th:text="\$\{swaggerUIEnabled\}"[^>]*>[^<]*</span>' , f'<span>{ self .mock_data ["swaggerUIEnabled" ]} </span>' ),
126+ (r'<span[^>]*th:text="\$\{springdocenabled\}"[^>]*>[^<]*</span>' , f'<span>{ self .mock_data ["springdocenabled" ]} </span>' ),
127+ (r'<span[^>]*th:text="\$\{swaggerURI\}"[^>]*>[^<]*</span>' , f'<span>{ self .mock_data ["swaggerURI" ]} </span>' ),
128+ (r'<span[^>]*th:text="\$\{#strings\.replace\(environment,\'_\',\' _\'\)\}"[^>]*>[^<]*</span>' , f'<span>{ self .mock_data ["environment" ]} </span>' ),
129+ (r'<p[^>]*th:text="\'Total score: \'\+\$\{totalScore\}"[^>]*>[^<]*</p>' , f'<p>Total score: { self .mock_data ["totalScore" ]} </p>' ),
130+ ]
131+
132+ for pattern , replacement in patterns :
133+ content = re .sub (pattern , replacement , content )
134+
135+ # Also handle simple th:text attributes without full element matching
136+ simple_replacements = {
137+ r'th:text="\$\{totalScore\}"' : '' ,
138+ r'th:text="\$\{sessioncounter\}"' : '' ,
139+ r'th:text="\$\{canaryCounter\}"' : '' ,
140+ r'th:text="\$\{lastCanaryToken\}"' : '' ,
141+ r'th:text="\$\{hintsEnabled\}"' : '' ,
142+ r'th:text="\$\{reasonEnabled\}"' : '' ,
143+ r'th:text="\$\{ctfModeEnabled\}"' : '' ,
144+ r'th:text="\$\{spoilingEnabled\}"' : '' ,
145+ r'th:text="\$\{swaggerUIEnabled\}"' : '' ,
146+ r'th:text="\$\{springdocenabled\}"' : '' ,
147+ r'th:text="\$\{swaggerURI\}"' : '' ,
148+ r'th:text="\$\{#strings\.replace\(environment,\'_\',\' _\'\)\}"' : '' ,
149+ r'th:text="\'Total score: \'\+\$\{totalScore\}"' : '' ,
129150 }
130151
131- for pattern , replacement in replacements .items ():
152+ for pattern , replacement in simple_replacements .items ():
132153 content = re .sub (pattern , replacement , content )
133154
134155 return content
0 commit comments