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
The following commit(s) were added to refs/heads/DOXIA-668 by this push: new e7254b3c Try with table border e7254b3c is described below commit e7254b3ccb3c58460d6d0d87851a66fcad9f607b Author: Michael Osipov <micha...@apache.org> AuthorDate: Thu Aug 4 20:42:47 2022 +0200 Try with table border --- .../apache/maven/doxia/parser/Xhtml5BaseParser.java | 20 ++++++++++++++++++-- .../apache/maven/doxia/sink/impl/Xhtml5BaseSink.java | 5 +++-- .../maven/doxia/parser/Xhtml5BaseParserTest.java | 4 ++-- .../maven/doxia/module/xhtml5/Xhtml5SinkTest.java | 4 ++-- .../src/test/resources/test.xhtml | 2 +- 5 files changed, 26 insertions(+), 9 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 203cc2f8..8e9cbab4 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. @@ -389,8 +394,7 @@ public class Xhtml5BaseParser } else if ( parser.getName().equals( HtmlMarkup.TABLE.toString() ) ) { - sink.table( attribs ); - sink.tableRows( new int[0], false ); + handleTableStart( sink, attribs, parser ); } else if ( parser.getName().equals( HtmlMarkup.TR.toString() ) ) { @@ -1205,4 +1209,16 @@ public class Xhtml5BaseParser sink.section_( sectionLevel-- ); } + private void handleTableStart( Sink sink, SinkEventAttributeSet attribs, XmlPullParser parser ) + { + sink.table( attribs ); + String givenTableClass = parser.getAttributeValue( null, Attribute.CLASS.toString() ); + boolean grid = false; + if ( givenTableClass != null && BODYTABLEBORDER_CLASS_PATTERN.matcher( givenTableClass ).matches() ) + { + grid = true; + } + sink.tableRows( new int[0], grid ); + } + } 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 f0c814c1..d8ccda0f 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 @@ -1374,7 +1374,8 @@ public class Xhtml5BaseSink /** * The default class style is <code>bodyTable</code>. - * Note: both parameters are ignored because they have been superseded by CSS in HTML5. + * + * @param grid if {@code true} the default class {@code bodyTableBorder} will be added * * {@inheritDoc} * @see javax.swing.text.html.HTML.Tag#TABLE @@ -1386,7 +1387,7 @@ public class Xhtml5BaseSink 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/parser/Xhtml5BaseParserTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/parser/Xhtml5BaseParserTest.java index 05c073f4..895388c8 100644 --- a/doxia-core/src/test/java/org/apache/maven/doxia/parser/Xhtml5BaseParserTest.java +++ b/doxia-core/src/test/java/org/apache/maven/doxia/parser/Xhtml5BaseParserTest.java @@ -160,7 +160,7 @@ public class Xhtml5BaseParserTest { // TODO: table caption, see DOXIA-177 - String text = "<table align=\"center\"><tr><th>Header</th></tr><tr><td>cell</td></tr></table>"; + String text = "<table><tr><th>Header</th></tr><tr><td>cell</td></tr></table>"; parser.parse( text, sink ); @@ -797,7 +797,7 @@ public class Xhtml5BaseParserTest public void testAttributeEntities() throws Exception { - String text = "<script type=\"text/javascript\" src=\"http://ex.com/ex.js?v=l&l=e\"></script>"; + String text = "<script src=\"http://ex.com/ex.js?v=l&l=e\"></script>"; parser.parse( text, sink ); 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..a6e4dfdf 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 @@ -112,7 +112,7 @@ public class Xhtml5SinkTest protected String getHeadBlock() { return "<!DOCTYPE html\">" + - "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<title></title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/></head>"; + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<title></title>\n<meta charset=\"UTF-8\"/></head>"; } /** {@inheritDoc} */ @@ -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 738c92bd..e98d00c5 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 style="text-align: center;"><i>Figure caption</i></p> </div> -<table style="margin-left: auto; margin-right: auto;" class="bodyTable"> +<table style="margin-left: auto; margin-right: auto;" class="bodyTable bodyTableBorder"> <caption>Table caption</caption> <tr class="a"> <th style="text-align: center;">Centered<br />cell 1,1</th>