import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

/**
 * Reproducer for
 * <a href="https://bugs.openjdk.org/browse/JDK-8179316">JDK-8179316</a>:
 * Incorrect rendering of tab chars inside html/pre/span.
 */
public final class HTMLTabsInSpan {
    private static final String HTML = """
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <title>Tabs In &lt;span&gt;</title>
                <style>
                pre {font-size:20pt; font-family: 'Courier New'}
                span {background-color: #aaccff}
                </style>
            </head>
            <body>
                <pre>l&#9;l&#9;l&#9;l&#9;l&#9;l&#9;l</pre>
                <pre><span>&#9;t</span>l</pre>
                <pre>&#9;<span>&#9;t</span>l</pre>
                <pre>&#9;&#9;<span>&#9;t</span>l</pre>
                <pre>&#9;&#9;&#9;<span>&#9;t</span>l</pre>
                <pre>&#9;&#9;&#9;&#9;<span>&#9;t</span>l</pre>
                <pre>&#9;&#9;&#9;&#9;&#9;<span>&#9;t</span></pre>
                <pre>l&#9;l&#9;l&#9;l&#9;l&#9;l&#9;l</pre>
            </body>
            </html>
            """;


    public static void main(String[] args) {
        SwingUtilities.invokeLater(HTMLTabsInSpan::createUI);
    }

    private static void createUI() {
        JEditorPane html = new JEditorPane("text/html", HTML);
        html.setEditable(false);

        JFrame frame = new JFrame("Tabs in <span>");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.add(new JScrollPane(html));

        frame.pack();

        frame.setLocationByPlatform(true);
        frame.setVisible(true);
    }
}
