001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.bean.html5; 018 019import static org.apache.juneau.marshall.xml.XmlFormat.*; 020 021import java.util.*; 022 023import org.apache.juneau.commons.bean.*; 024import org.apache.juneau.marshall.*; 025import org.apache.juneau.marshall.xml.*; 026 027/** 028 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/grouping-content.html#the-pre-element"><pre></a> 029 * element. 030 * 031 * <p> 032 * The pre element represents a block of preformatted text, in which structure is represented 033 * by typographic conventions rather than by elements. It is used to display text exactly as 034 * it is written, preserving whitespace, line breaks, and formatting. The pre element is 035 * typically rendered in a monospace font and is commonly used for displaying code snippets, 036 * ASCII art, or any text where formatting and spacing are important. 037 * 038 * <h5 class='section'>Examples:</h5> 039 * <p class='bcode w800'> 040 * <jk>import static</jk> org.apache.juneau.bean.html5.HtmlBuilder.*; 041 * 042 * <jc>// Simple preformatted text</jc> 043 * Pre <jv>simple</jv> = <jsm>pre</jsm>(<js>"This text preserves\n all formatting\n and spacing."</js>); 044 * 045 * <jc>// Pre with styling</jc> 046 * Pre <jv>styled</jv> = <jsm>pre</jsm>(<js>"function hello() {\n return 'Hello World';\n}"</js>) 047 * .class_(<js>"code-block"</js>); 048 * 049 * <jc>// Pre with complex content</jc> 050 * Pre <jv>complex</jv> = <jsm>pre</jsm>( 051 * <js>" "</js>, 052 * <jsm>strong</jsm>(<js>"Bold text"</js>), 053 * <js>" in preformatted content\n"</js>, 054 * <js>" "</js>, 055 * <jsm>em</jsm>(<js>"Italic text"</js>), 056 * <js>" with preserved formatting"</js> 057 * ); 058 * 059 * <jc>// Pre with ID</jc> 060 * Pre <jv>withId</jv> = <jsm>pre</jsm>(<js>"console.log('Hello World');"</js>) 061 * .id(<js>"code-example"</js>); 062 * 063 * <jc>// Pre with styling</jc> 064 * Pre <jv>styled2</jv> = <jsm>pre</jsm>(<js>"This is styled preformatted text."</js>) 065 * .style(<js>"background-color: #f4f4f4; padding: 10px; border: 1px solid #ddd;"</js>); 066 * 067 * <jc>// Pre with multiple elements</jc> 068 * Pre <jv>multiple</jv> = <jsm>pre</jsm>( 069 * <js>"Line 1: "</js>, 070 * <jsm>span</jsm>(<js>"function"</js>).class_(<js>"keyword"</js>), 071 * " ", 072 * new Span().class_("function-name").children("example"), 073 * "() {\n", 074 * "Line 2: ", 075 * new Span().class_("keyword").children("return"), 076 * " ", 077 * new Span().class_("string").children("'Hello'"), 078 * ";\n", 079 * "Line 3: }" 080 * ); 081 * 082 * // Pre with code 083 * Pre withCode = new Pre() 084 * .children( 085 * new Code().children("const message = 'Hello World';\nconsole.log(message);") 086 * ); 087 * </p> 088 * 089 * <p> 090 * The following convenience methods are provided for constructing instances of this bean: 091 * <ul class='javatree'> 092 * <li class='jc'>{@link HtmlBuilder} 093 * <ul class='javatree'> 094 * <li class='jm'>{@link HtmlBuilder#pre() pre()} 095 * <li class='jm'>{@link HtmlBuilder#pre(Object...) pre(Object...)} 096 * </ul> 097 * </ul> 098 * </p> 099 * 100 * <h5 class='section'>See Also:</h5><ul> 101 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a> 102 * </ul> 103 */ 104@Marshalled(typeName = "pre") 105public class Pre extends HtmlElementMixed<Pre> { 106 107 /** 108 * Creates an empty {@link Pre} element. 109 */ 110 public Pre() {} 111 112 /** 113 * Creates a {@link Pre} element with the specified child nodes. 114 * 115 * @param children The child nodes. Must not be <jk>null</jk>. 116 */ 117 public Pre(Object...children) { 118 children(children); 119 } 120 121 @Xml(format = MIXED_PWS) 122 @BeanProp(name="c") @MarshalledProp(dictionary=HtmlBeanDictionary.class) 123 @Override 124 public List<Object> getChildren() { return super.getChildren(); } 125 126}