This is an automated email from the ASF dual-hosted git repository. michaelo pushed a commit to branch DOXIA-668 in repository https://gitbox.apache.org/repos/asf/maven-doxia.git
commit be34bdd7119acb8c101b54265b833f54477ff944 Author: Michael Osipov <[email protected]> AuthorDate: Sat Oct 1 21:19:45 2022 +0200 [DOXIA-674] Replace table border handling with new CSS class --- .../org/apache/maven/doxia/parser/Xhtml5BaseParser.java | 14 +++++++++----- .../org/apache/maven/doxia/sink/impl/Xhtml5BaseSink.java | 9 +++------ .../apache/maven/doxia/sink/impl/Xhtml5BaseSinkTest.java | 14 +++++++------- .../apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java | 2 +- .../doxia-module-xhtml5/src/test/resources/test.xhtml | 4 ++-- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/parser/Xhtml5BaseParser.java b/doxia-core/src/main/java/org/apache/maven/doxia/parser/Xhtml5BaseParser.java index 52b2381f..7be70b6b 100644 --- a/doxia-core/src/main/java/org/apache/maven/doxia/parser/Xhtml5BaseParser.java +++ b/doxia-core/src/main/java/org/apache/maven/doxia/parser/Xhtml5BaseParser.java @@ -21,6 +21,7 @@ package org.apache.maven.doxia.parser; import java.io.Reader; import java.util.Stack; +import java.util.regex.Pattern; import javax.swing.text.html.HTML.Attribute; @@ -46,6 +47,10 @@ public class Xhtml5BaseParser { private static final Logger LOGGER = LoggerFactory.getLogger( Xhtml5BaseParser.class ); + /** Used to identify if a class string contains `bodyTableBorder` */ + private static final Pattern BODYTABLEBORDER_CLASS_PATTERN = + Pattern.compile( "(?:.*\\s|^)bodyTableBorder(?:\\s.*|$)" ); + /** * True if a <script></script> or <style></style> block is read. CDATA sections within are * handled as rawText. @@ -1207,12 +1212,11 @@ public class Xhtml5BaseParser private void handleTableStart( Sink sink, SinkEventAttributeSet attribs, XmlPullParser parser ) { sink.table( attribs ); - String border = parser.getAttributeValue( null, Attribute.BORDER.toString() ); - boolean grid = true; - - if ( border == null || "0".equals( border ) ) + String givenTableClass = parser.getAttributeValue( null, Attribute.CLASS.toString() ); + boolean grid = false; + if ( givenTableClass != null && BODYTABLEBORDER_CLASS_PATTERN.matcher( givenTableClass ).matches() ) { - grid = false; + grid = true; } String align = parser.getAttributeValue( null, Attribute.ALIGN.toString() ); diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSink.java b/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSink.java index 1364d71b..b0c5b93c 100644 --- a/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSink.java +++ b/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSink.java @@ -1438,7 +1438,8 @@ public class Xhtml5BaseSink /** * The default class style is <code>bodyTable</code>. - * The default align is <code>center</code>. + * + * @param grid if {@code true} the default class {@code bodyTableBorder} will be added * * {@inheritDoc} * @see javax.swing.text.html.HTML.Tag#TABLE @@ -1449,14 +1450,10 @@ public class Xhtml5BaseSink setCellJustif( justification ); MutableAttributeSet att = new SinkEventAttributeSet(); - if ( !this.tableAttributes.isDefined( Attribute.BORDER.toString() ) ) - { - att.addAttribute( Attribute.BORDER, ( grid ? "1" : "0" ) ); - } if ( !this.tableAttributes.isDefined( Attribute.CLASS.toString() ) ) { - att.addAttribute( Attribute.CLASS, "bodyTable" ); + att.addAttribute( Attribute.CLASS, "bodyTable" + ( grid ? " bodyTableBorder" : "" ) ); } att.addAttributes( this.tableAttributes ); diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSinkTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSinkTest.java index 5e4aedc1..87ca4109 100644 --- a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSinkTest.java +++ b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSinkTest.java @@ -169,11 +169,11 @@ public class Xhtml5BaseSinkTest String actual = writer.toString(); assertTrue( - actual.contains( "<table border=\"0\" class=\"bodyTable\">" + "<caption>caption&1</caption>" ) ); + actual.contains( "<table class=\"bodyTable\">" + "<caption>caption&1</caption>" ) ); assertTrue( actual.contains( - "<table border=\"0\" class=\"bodyTable\" align=\"left\">" + "<caption>caption2</caption>" ) ); + "<table class=\"bodyTable\" align=\"left\">" + "<caption>caption2</caption>" ) ); assertTrue( actual.contains( - "<table border=\"0\" class=\"bodyTable\" align=\"right\">" + "<caption>caption3</caption>" ) ); + "<table class=\"bodyTable\" align=\"right\">" + "<caption>caption3</caption>" ) ); assertTrue( actual.contains( "<td align=\"center\">cell11</td>" ) ); assertTrue( actual.contains( "<td align=\"left\">nestedTable1Cell11</td>" ) ); @@ -1074,7 +1074,7 @@ public class Xhtml5BaseSinkTest sink.close(); } - assertEquals( "<table border=\"0\" class=\"bodyTable\"></table>", writer.toString() ); + assertEquals( "<table class=\"bodyTable\"></table>", writer.toString() ); } /** @@ -1101,7 +1101,7 @@ public class Xhtml5BaseSinkTest sink.close(); } - String xmlExpected = "<table border=\"0\" class=\"bodyTable\">" + EOL + "<tr style=\"bold\" class=\"a\"></tr>" + String xmlExpected = "<table class=\"bodyTable\">" + EOL + "<tr style=\"bold\" class=\"a\"></tr>" + EOL + "<tr class=\"b\"></tr></table>"; assertEquals( xmlExpected, writer.toString() ); @@ -1156,7 +1156,7 @@ public class Xhtml5BaseSinkTest sink.close(); } - StringBuilder sbExpeted = new StringBuilder( "<table border=\"0\" class=\"bodyTable\">" ); + StringBuilder sbExpeted = new StringBuilder( "<table class=\"bodyTable\">" ); sbExpeted.append( EOL ).append( "<tr class=\"a\"></tr>" ).append( EOL ); sbExpeted.append( "<tr style=\"bold\" class=\"b\"></tr>" ).append( EOL ); sbExpeted.append( "<tr class=\"hidden xyz abc a\"></tr>" ).append( EOL ); @@ -1238,7 +1238,7 @@ public class Xhtml5BaseSinkTest } assertEquals( - "<table border=\"0\" class=\"bodyTable\">" + "<caption style=\"bold\">caption</caption></table>", + "<table class=\"bodyTable\">" + "<caption style=\"bold\">caption</caption></table>", writer.toString() ); } diff --git a/doxia-modules/doxia-module-xhtml5/src/test/java/org/apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java b/doxia-modules/doxia-module-xhtml5/src/test/java/org/apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java index 9b900454..2d95a466 100644 --- a/doxia-modules/doxia-module-xhtml5/src/test/java/org/apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java +++ b/doxia-modules/doxia-module-xhtml5/src/test/java/org/apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java @@ -226,7 +226,7 @@ public class Xhtml5SinkTest /** {@inheritDoc} */ protected String getTableBlock( String cell, String caption ) { - return "<table border=\"0\" class=\"bodyTable\">" + return "<table class=\"bodyTable\">" + "<caption>Table caption</caption><tr class=\"a\">\n<td>cell</td></tr>" + "</table>"; } diff --git a/doxia-modules/doxia-module-xhtml5/src/test/resources/test.xhtml b/doxia-modules/doxia-module-xhtml5/src/test/resources/test.xhtml index 7fa89509..5b643c70 100644 --- a/doxia-modules/doxia-module-xhtml5/src/test/resources/test.xhtml +++ b/doxia-modules/doxia-module-xhtml5/src/test/resources/test.xhtml @@ -79,7 +79,7 @@ under the License. <p align="center"><i>Figure caption</i></p> </div> -<table align="center" border="1" class="bodyTable"> +<table align="center" class="bodyTable bodyTableBorder"> <caption>Table caption</caption> <tr class="a"> <th align="center">Centered<br />cell 1,1</th> @@ -95,7 +95,7 @@ under the License. <p>No grid, no caption:</p> -<table align="center" border="0" class="bodyTable"> +<table align="center" class="bodyTable"> <tr class="a"> <td align="center">cell</td> <td align="center">cell</td>
