This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jrst. See http://git.nuiton.org/jrst.git commit a12bbd4c468e9247a21b22543858f262c6a2b03d Author: Eric Chatellier <chatellier@codelutin.com> Date: Wed Apr 29 18:00:23 2015 +0200 refs #3683: add support for custom classes --- jrst/src/main/resources/xsl/rst2xhtml.xsl | 82 ++++++++++++---- .../java/org/nuiton/jrst/JRSTAbstractTest.java | 9 +- .../test/java/org/nuiton/jrst/bugs/HtmlTest.java | 63 ++++++++++++ .../test/java/org/nuiton/jrst/bugs/TableTest.java | 2 - .../test/resources/bugs/testCustomClasses3683.rst | 107 +++++++++++++++++++++ 5 files changed, 241 insertions(+), 22 deletions(-) diff --git a/jrst/src/main/resources/xsl/rst2xhtml.xsl b/jrst/src/main/resources/xsl/rst2xhtml.xsl index f4a1314..c24a28c 100644 --- a/jrst/src/main/resources/xsl/rst2xhtml.xsl +++ b/jrst/src/main/resources/xsl/rst2xhtml.xsl @@ -3,7 +3,7 @@ #%L JRst :: Api %% - Copyright (C) 2004 - 2010 CodeLutin + Copyright (C) 2004 - 2015 CodeLutin, Chatellier Eric %% This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -31,7 +31,7 @@ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> - <meta name="generator" content="JRST http://maven-site.nuiton.org/jrst" /> + <meta name="generator" content="JRST https://jrst.nuiton.org/" /> <title><xsl:value-of select="title"/></title> </head> <body> @@ -50,14 +50,15 @@ <xsl:template match="title"> <xsl:if test="name(..)='document'"> - <h1 class="mainTitle"> + <h1> + <xsl:attribute name="class"><xsl:value-of select="normalize-space(concat('mainTitle', ' ', @classes))" /></xsl:attribute> <xsl:apply-templates/> </h1> </xsl:if> <xsl:if test="not(name(..)='document')"> <xsl:element name="h{count(ancestor::section) + 1}"> - <xsl:attribute name="class">title</xsl:attribute> + <xsl:attribute name="class"><xsl:value-of select="normalize-space(concat('title', ' ', ../@classes))" /></xsl:attribute> <xsl:if test="@refid"> <a class="toc-backref" href="#{@refid}" id="{../@id}"><xsl:apply-templates/></a> </xsl:if> @@ -70,6 +71,7 @@ <xsl:template match="subtitle"> <xsl:element name="h2"> + <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if> <xsl:apply-templates/> </xsl:element> </xsl:template> @@ -144,7 +146,7 @@ <xsl:apply-templates/> </xsl:template> - <xsl:template match="list_item/paragraph[1] | definition_list_item/*/paragraph[1] | field/*/paragraph[1] | option/*/paragraph[1]"> + <xsl:template match="list_item/paragraph[position()=1 and not(@classes)] | definition_list_item/*/paragraph[position()=1 and not(@classes)] | field/*/paragraph[1] | option/*/paragraph[1]"> <!--XXX - Unclear how to handle multi-paragraph list items. | Certainly when they're single paragraphs, we don't want them | wrapped in a <P> tag. This seems to work okay. @@ -153,7 +155,10 @@ </xsl:template> <xsl:template match="paragraph"> - <p><xsl:apply-templates/></p> + <p> + <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if> + <xsl:apply-templates/> + </p> </xsl:template> <xsl:template match="reference"> @@ -166,23 +171,45 @@ </xsl:template> <xsl:template match="emphasis"> - <em><xsl:apply-templates/></em> + <em> + <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if> + <xsl:apply-templates/> + </em> </xsl:template> <xsl:template match="strong"> - <b><xsl:apply-templates/></b> + <b> + <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if> + <xsl:apply-templates/> + </b> </xsl:template> <xsl:template match="literal"> - <code><xsl:value-of select="text()"/></code> + <code> + <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if> + <xsl:value-of select="text()"/> + </code> </xsl:template> - + + <xsl:template match="inline"> + <span> + <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if> + <xsl:value-of select="text()"/> + </span> + </xsl:template> + <xsl:template match="literal_block"> - <pre class="literal_block"><xsl:value-of select="text()"/></pre> + <pre> + <xsl:attribute name="class"><xsl:value-of select="normalize-space(concat('literal_block', ' ', @classes))" /></xsl:attribute> + <xsl:value-of select="text()"/> + </pre> </xsl:template> <xsl:template match="bullet_list"> - <ul><xsl:apply-templates/></ul> + <ul> + <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if> + <xsl:apply-templates/> + </ul> </xsl:template> <xsl:template match="enumerated_list"> @@ -205,12 +232,16 @@ </xsl:when> </xsl:choose> <xsl:copy-of select="@start"/> + <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if> <xsl:apply-templates/> </ol> </xsl:template> <xsl:template match="list_item"> - <li><p><xsl:apply-templates/></p></li> + <li> + <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if> + <xsl:apply-templates/> + </li> </xsl:template> <xsl:template match="field_list"> @@ -245,7 +276,10 @@ </xsl:template> <xsl:template match="definition_list"> - <dl class="definition_list"><xsl:apply-templates/></dl> + <dl> + <xsl:attribute name="class"><xsl:value-of select="normalize-space(concat('definition_list', ' ', @classes))" /></xsl:attribute> + <xsl:apply-templates/> + </dl> </xsl:template> <xsl:template match="definition_list_item"> @@ -253,7 +287,11 @@ </xsl:template> <xsl:template match="term"> - <dt class="term"><xsl:apply-templates/><xsl:call-template name="classifier"/></dt> + <dt> + <xsl:attribute name="class"><xsl:value-of select="normalize-space(concat('term', ' ', @classes))" /></xsl:attribute> + <xsl:apply-templates/> + <xsl:call-template name="classifier"/> + </dt> </xsl:template> <xsl:template name="classifier"> @@ -267,7 +305,9 @@ </xsl:template> <xsl:template match="definition"> - <dd class="definition"><xsl:apply-templates/></dd> + <dd> + <xsl:apply-templates/> + </dd> </xsl:template> <xsl:template match="image"> @@ -297,6 +337,7 @@ <xsl:template name="img"> <xsl:element name="img"> + <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if> <xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute> <xsl:attribute name="src"><xsl:value-of select="@uri"/></xsl:attribute> <xsl:if test="@width"><xsl:attribute name="width"><xsl:value-of select="@width"/></xsl:attribute></xsl:if> @@ -321,6 +362,7 @@ +--> <xsl:template match="table"> <table border="1"> + <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if> <colgroup> <xsl:apply-templates select="tgroup/colspec"/> </colgroup> @@ -361,7 +403,8 @@ </xsl:template> <xsl:template match="admonition"> - <div class="admonition"> + <div> + <xsl:attribute name="class"><xsl:value-of select="normalize-space(concat('admonition', ' ', @classes))" /></xsl:attribute> <div class="{@class}"> <p class="{title}"> <xsl:apply-templates select="./title"/> @@ -374,7 +417,8 @@ </xsl:template> <xsl:template match="attention|caution|danger|error|hint|important|note|tip|warning"> - <div class="{name(.)}"> + <div> + <xsl:attribute name="class"><xsl:value-of select="normalize-space(concat(name(.), ' ', @classes))" /></xsl:attribute> <p class="title"><xsl:value-of select="name(.)"/> :</p> <p class="body"> <xsl:apply-templates/> @@ -383,8 +427,8 @@ </xsl:template> <xsl:template match="block_quote"> - <blockquote> + <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if> <xsl:if test="./attribution"> <p><xsl:apply-templates select="child::*[position()=1]"/></p> <p class="attribution"> diff --git a/jrst/src/test/java/org/nuiton/jrst/JRSTAbstractTest.java b/jrst/src/test/java/org/nuiton/jrst/JRSTAbstractTest.java index ba1beeb..b991b7d 100644 --- a/jrst/src/test/java/org/nuiton/jrst/JRSTAbstractTest.java +++ b/jrst/src/test/java/org/nuiton/jrst/JRSTAbstractTest.java @@ -107,15 +107,22 @@ public class JRSTAbstractTest extends Assert { } public void generate() throws Exception { + generateSimple(); + generateDocutils(); + } + + protected void generateSimple() throws Exception { TimeLog simpleModeTimeLog = new TimeLog("Simple Mode"); simpleModeTimeLog.setTimeToLogInfo(100l); Long start = TimeLog.getTime(); JRST.generate(outputType, in, out, overwrite, true); simpleModeTimeLog.log(start, "Simple Mode generation"); assertJRST(in, out); + } + protected void generateDocutils() throws Exception { TimeLog docutilsTimeLog = new TimeLog("DocUtils"); - start = TimeLog.getTime(); + Long start = TimeLog.getTime(); JRST.generate(outputType, in, out, overwrite, false); docutilsTimeLog.log(start, "DocUtils generation"); assertJRST(in, out); diff --git a/jrst/src/test/java/org/nuiton/jrst/bugs/HtmlTest.java b/jrst/src/test/java/org/nuiton/jrst/bugs/HtmlTest.java new file mode 100644 index 0000000..80060bf --- /dev/null +++ b/jrst/src/test/java/org/nuiton/jrst/bugs/HtmlTest.java @@ -0,0 +1,63 @@ +/* + * #%L + * JRst :: Api + * %% + * Copyright (C) 2015 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.jrst.bugs; + +import java.io.File; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.jrst.JRST; +import org.nuiton.jrst.JRSTAbstractTest; + +/** + * Test related to html specific output. + * + * @author chatellier + */ +public class HtmlTest extends JRSTAbstractTest { + + /** + * Test that custom classes is supported on various elements. + */ + @Test + public void testClassesSupport() throws Exception { + File in = getBugTestFile("testCustomClasses3683.rst"); + File out = getOutputTestFile("jrst-customClasses.html"); + + new JRSTTestGenerator(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME) { + + // skip simple mode + protected void generateSimple() { + // someone motivated can fix it in simple mode + } + + @Override + public void assertJRST(File in, File out) throws Exception { + String content = FileUtils.readFileToString(out, JRST.UTF_8); + for (int i = 1; i <= 14; i++) { + Assert.assertTrue("Missing style specialformat" + i, content.contains("specialformat" + i + "\"")); + } + } + }; + } + +} diff --git a/jrst/src/test/java/org/nuiton/jrst/bugs/TableTest.java b/jrst/src/test/java/org/nuiton/jrst/bugs/TableTest.java index 22b7561..6ac4298 100644 --- a/jrst/src/test/java/org/nuiton/jrst/bugs/TableTest.java +++ b/jrst/src/test/java/org/nuiton/jrst/bugs/TableTest.java @@ -50,7 +50,6 @@ public class TableTest extends JRSTAbstractTest { public void testTableSpecialChar() throws Exception { File in = getBugTestFile("testTable1290.rst"); File out = getOutputTestFile("jrst-tables.html"); -// out.deleteOnExit(); new JRSTTestGenerator(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME) { @@ -72,7 +71,6 @@ public class TableTest extends JRSTAbstractTest { public void testTableIndentation() throws Exception { File in = getBugTestFile("testTable1375.rst"); File out = getOutputTestFile("jrst-tables.html"); -// out.deleteOnExit(); new JRSTTestGenerator(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME) { diff --git a/jrst/src/test/resources/bugs/testCustomClasses3683.rst b/jrst/src/test/resources/bugs/testCustomClasses3683.rst new file mode 100644 index 0000000..55b12bf --- /dev/null +++ b/jrst/src/test/resources/bugs/testCustomClasses3683.rst @@ -0,0 +1,107 @@ +.. - +.. * #%L +.. * JRst :: Api +.. * %% +.. * Copyright (C) 2004 - 2010 CodeLutin +.. * %% +.. * This program is free software: you can redistribute it and/or modify +.. * it under the terms of the GNU Lesser General Public License as +.. * published by the Free Software Foundation, either version 3 of the +.. * License, or (at your option) any later version. +.. * +.. * This program is distributed in the hope that it will be useful, +.. * but WITHOUT ANY WARRANTY; without even the implied warranty of +.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.. * GNU General Lesser Public License for more details. +.. * +.. * You should have received a copy of the GNU General Lesser Public +.. * License along with this program. If not, see +.. * <http://www.gnu.org/licenses/lgpl-3.0.html>. +.. * #L% +.. - + +Test missing classes support +============================ + +Test with litteral_block. + +.. class:: specialFormat1 + +:: + + public class Test { + + } + +.. class:: specialFormat2 +.. + + public class Test2 { + + } + +:: + + public class Test3 { + + } + +Test with basic paragraph. + +.. class:: specialFormat3 + +test + +.. class:: specialFormat4 + +Test with title +--------------- + +Test on subtitle. + +.. role:: specialformat5 + +And with :specialformat5:`test`. + + +.. class:: specialFormat6 + +* listItem1 + +.. class:: specialFormat7 + +1. listItem1 + + .. class:: specialFormat8 +2. listItem1 + +.. class:: specialFormat9 + +- listItem1 + +.. class:: specialFormat10 + +term 1 + Definition 1. +term 2 + .. class:: specialFormat11 + + Definition 2. + + .. class:: specialFormatx +term3 + Not working (even in rst2html). + +.. image:: test + :class: specialFormat12 + + +.. image:: test + :target: _blank + :class: specialFormat13 + +.. image:: test + :target: _blank + :align: center + :class: specialFormat14 + -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.