Class Pre


@Bean(typeName="pre") public class Pre extends HtmlElementMixed
DTO for an HTML <pre> element.

The pre element represents a block of preformatted text, in which structure is represented by typographic conventions rather than by elements. It is used to display text exactly as it is written, preserving whitespace, line breaks, and formatting. The pre element is typically rendered in a monospace font and is commonly used for displaying code snippets, ASCII art, or any text where formatting and spacing are important.

Examples:

import static org.apache.juneau.bean.html5.HtmlBuilder.*; // Simple preformatted text Pre simple = pre("This text preserves\n all formatting\n and spacing."); // Pre with styling Pre styled = pre("function hello() {\n return 'Hello World';\n}") ._class("code-block"); // Pre with complex content Pre complex = pre( " ", strong("Bold text"), " in preformatted content\n", " ", em("Italic text"), " with preserved formatting" ); // Pre with ID Pre withId = pre("console.log('Hello World');") .id("code-example"); // Pre with styling Pre styled2 = pre("This is styled preformatted text.") .style("background-color: #f4f4f4; padding: 10px; border: 1px solid #ddd;"); // Pre with multiple elements Pre multiple = pre( "Line 1: ", span("function")._class("keyword"), " ", new Span()._class("function-name").children("example"), "() {\n", "Line 2: ", new Span()._class("keyword").children("return"), " ", new Span()._class("string").children("'Hello'"), ";\n", "Line 3: }" ); // Pre with code Pre withCode = new Pre() .children( new Code().children("const message = 'Hello World';\nconsole.log(message);") );

The following convenience methods are provided for constructing instances of this bean:

See Also: