Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bindings/java/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Added

- `CssInline.inline(String html, String css)` convenience overload for applying a CSS string to a full HTML document. [#693](https://github.com/Stranger6667/css-inline/issues/693)

### Fixed

- `inlineFragment` silently returning only leading whitespace when the input starts with whitespace. [#692](https://github.com/Stranger6667/css-inline/issues/692)
Expand Down
6 changes: 6 additions & 0 deletions bindings/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ public class Example {
}
```

To apply a CSS string directly to a document, use the `inline(html, css)` shortcut:

```java
String inlined = CssInline.inline(html, "h1 { color: blue; }");
```

You can also configure the inlining process:

```java
Expand Down
16 changes: 16 additions & 0 deletions bindings/java/src/main/java/org/cssinline/CssInline.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ public static String inline(String html, CssInlineConfig cfg) {
return nativeInline(html, cfg);
}

/**
* Inlines the provided CSS into an HTML document using default configuration.
*
* <p>This is a convenience shortcut for applying a CSS string to a full HTML document.
* Equivalent to building a config with {@code setExtraCss(css)} and calling
* {@link #inline(String, CssInlineConfig)}.
*
* @param html the HTML document to process
* @param css the CSS rules to inline
* @return the HTML document with CSS styles inlined
* @throws CssInlineException if an error occurs during processing
*/
public static String inline(String html, String css) {
return inline(html, new CssInlineConfig.Builder().setExtraCss(css).build());
}

/**
* Inlines CSS styles into HTML elements using default configuration.
*
Expand Down
9 changes: 9 additions & 0 deletions bindings/java/src/test/java/org/cssinline/CssInlineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ void inlinesSimpleStyleTag() {
assertTrue(out.contains("style=\"color: blue;\""), "Output should inline styles for h1, got: " + out);
}

@Test
void inlineWithCssShortcut() {
String html = "<html><head></head><body><h1>Hello</h1></body></html>";

String out = CssInline.inline(html, "h1 { color: blue; }");

assertEquals("<html><head></head><body><h1 style=\"color: blue;\">Hello</h1></body></html>", out);
}

@Test
void extraCssAddsBackground() {
String html = "<html><head></head><body><h1>Hello</h1></body></html>";
Expand Down
Loading