File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,8 @@ class CssInliner
6868 * @param int $preallocateNodeCapacity Pre-allocate capacity for HTML nodes
6969 * @param StylesheetCache|null $cache Cache for external stylesheets
7070 * @param bool $removeInlinedSelectors Remove selectors that were successfully inlined from style blocks
71+ * @param bool $applyWidthAttributes Add width HTML attributes from CSS width properties on supported elements
72+ * @param bool $applyHeightAttributes Add height HTML attributes from CSS height properties on supported elements
7173 */
7274 public function __construct (
7375 bool $ inlineStyleTags = true ,
@@ -81,6 +83,8 @@ public function __construct(
8183 int $ preallocateNodeCapacity = 32 ,
8284 ?StylesheetCache $ cache = null ,
8385 bool $ removeInlinedSelectors = false ,
86+ bool $ applyWidthAttributes = false ,
87+ bool $ applyHeightAttributes = false ,
8488 ) {}
8589
8690 /**
Original file line number Diff line number Diff line change @@ -276,6 +276,30 @@ public function testLoadRemoteStylesheetsDisabled(): void
276276 $ this ->assertIsString ($ result );
277277 }
278278
279+ public function testApplyWidthAttributes (): void
280+ {
281+ $ inliner = new CssInliner (
282+ applyWidthAttributes: true ,
283+ );
284+
285+ $ html = '<html><head><style>td { width: 100px; }</style></head><body><table><tr><td>Test</td></tr></table></body></html> ' ;
286+ $ result = $ inliner ->inline ($ html );
287+
288+ $ this ->assertStringContainsString ('width="100" ' , $ result );
289+ }
290+
291+ public function testApplyHeightAttributes (): void
292+ {
293+ $ inliner = new CssInliner (
294+ applyHeightAttributes: true ,
295+ );
296+
297+ $ html = '<html><head><style>td { height: 50px; }</style></head><body><table><tr><td>Test</td></tr></table></body></html> ' ;
298+ $ result = $ inliner ->inline ($ html );
299+
300+ $ this ->assertStringContainsString ('height="50" ' , $ result );
301+ }
302+
279303 public function testRemoveInlinedSelectors (): void
280304 {
281305 $ inliner = new CssInliner (
You can’t perform that action at this time.
0 commit comments