Skip to content

Commit

Permalink
[DOXIA-616] Markdown: Properly expose the language specified in fence…
Browse files Browse the repository at this point in the history
…d code blocks

To properly implement this change the following task had to be performed:

* Properly expose language class in fenced code blocks
* Re-implemente metadata processing
* Add unit tests
* Add integration tests (with maven-site-plugin)
* Fix *XhtmlBaseParser* and *XhtmlBaseSink* to properly expose attributes of the PRE and CODE elements
* Fix *AbstractModuleTest* to use UTF-8 for input files
* Remove Pegdown emulation profile and embrace CommonMark

This closes #49
  • Loading branch information
bertysentry authored and michael-o committed Jan 2, 2021
1 parent d66b461 commit b55285c
Show file tree
Hide file tree
Showing 24 changed files with 715 additions and 328 deletions.
Expand Up @@ -509,7 +509,8 @@ else if ( ( parser.getName().equals( HtmlMarkup.CODE.toString() ) )
|| ( parser.getName().equals( HtmlMarkup.SAMP.toString() ) )
|| ( parser.getName().equals( HtmlMarkup.TT.toString() ) ) )
{
sink.inline( SinkEventAttributeSet.Semantics.CODE );
attribs.addAttributes( SinkEventAttributeSet.Semantics.CODE );
sink.inline( attribs );
}
else if ( parser.getName().equals( HtmlMarkup.A.toString() ) )
{
Expand Down
Expand Up @@ -1905,7 +1905,9 @@ private void inlineSemantics( SinkEventAttributes attributes, String semantic,
{
if ( attributes.containsAttribute( SinkEventAttributes.SEMANTICS, semantic ) )
{
writeStartTag( tag );
SinkEventAttributes attributesNoSemantics = ( SinkEventAttributes ) attributes.copyAttributes();
attributesNoSemantics.removeAttribute( SinkEventAttributes.SEMANTICS );
writeStartTag( tag, attributesNoSemantics );
tags.add( 0, tag );
}
}
Expand Down
Expand Up @@ -1782,7 +1782,9 @@ private void inlineSemantics( SinkEventAttributes attributes, String semantic,
{
if ( attributes.containsAttribute( SinkEventAttributes.SEMANTICS, semantic ) )
{
writeStartTag( tag );
SinkEventAttributes attributesNoSemantics = ( SinkEventAttributes ) attributes.copyAttributes();
attributesNoSemantics.removeAttribute( SinkEventAttributes.SEMANTICS );
writeStartTag( tag, attributesNoSemantics );
tags.add( 0, tag );
}
}
Expand Down
Expand Up @@ -30,6 +30,7 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.StandardCharsets;

/**
* Provide some common convenience methods to test Doxia modules (parsers and sinks).
Expand Down Expand Up @@ -172,7 +173,7 @@ protected Reader getTestReader( String baseName, String extension )

assertNotNull( "Could not find resource: " + baseName + "." + extension, is );

return new InputStreamReader( is );
return new InputStreamReader( is, StandardCharsets.UTF_8 );
}

/**
Expand Down
75 changes: 75 additions & 0 deletions doxia-modules/doxia-module-markdown/pom.xml
Expand Up @@ -72,5 +72,80 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies>
<build>

<plugins>

<!-- install -->
<plugin>
<artifactId>maven-install-plugin</artifactId>
<executions>

<!-- integration-test -->
<!-- Copy the Doxia XHTML module from our working directory to the local-repo -->
<!-- We do that manually because the invoker:install goal (below) doesn't do it, as -->
<!-- it's not the artifact we're working on, but the ones that are produced by our "siblings" -->
<execution>
<id>copy-doxia-module-xhtml-to-local-repo</id>
<phase>integration-test</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<file>${project.basedir}/../doxia-module-xhtml/target/doxia-module-xhtml-${project.version}.jar</file>
</configuration>
</execution>
<execution>
<id>copy-doxia-to-local-repo</id>
<phase>integration-test</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<file>${project.basedir}/../../doxia-core/target/doxia-core-${project.version}.jar</file>
</configuration>
</execution>
</executions>
</plugin>

<!-- maven-invoker-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<!-- <version>2.0.0</version> -->
<configuration>
<debug>false</debug>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>**/pom.xml</pomInclude>
</pomIncludes>
<postBuildHookScript>verify</postBuildHookScript>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<extraArtifacts></extraArtifacts>
<settingsFile>src/it/settings.xml</settingsFile>
<goals>
<goal>clean</goal>
<goal>site</goal>
</goals>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.doxia</groupId>
<artifactId>it</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<description>Project Description</description>

<build>
<plugins>

<!-- site -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
<configuration>
<generateReports>false</generateReports>
<generateProjectInfo>false</generateProjectInfo>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-core</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-module-xhtml</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</dependency>
</dependencies>

</plugin>

</plugins>
</build>

</project>
@@ -0,0 +1,26 @@
author: Bertrand Martin

# Fenced Code Block

This is Java code and must be tagged so such.

```java
// Fenced Code Block 1
System.out.println("Hello, Fenced Code Block!");
```

This is non-specified code:

```
# Fenced Code Block 2
ch = fopen("/tmp/test.log", "r");
```

This is similar to indented block:

// Indented Code Block
System.out.println("Hello, Indented Block");

And it is also different from the inline code: `System.out.println("Hello, Inline Code");`, which remains simple.

And what about ```System.out.println("Inline fenced code");```?
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<project name="${project.name} from site.xml">

<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.9</version>
</skin>

<body>

<menu name="Testing">
<item name="Fenced Code Block" href="fenced-code-block.html" />
</menu>

</body>
</project>
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// Verify fenced-code-block.html

// File was produced
File resultFile = new File(basedir, "target/site/fenced-code-block.html")
assert resultFile.isFile()

// Check the content
String content = resultFile.text;

// Our first fenced code block is <div class="source"><pre><code class="language-java">...</code></pre></div>
assert content =~ '<div class="source">.*<pre.*>.*<code.*class=".*language-java.*">.*// Fenced Code Block 1'

// Our second fenced code block doesn't specify a language
assert content =~ '<div class="source">.*<pre.*>.*<code.*># Fenced Code Block 2'
assert !(content =~ '<div class="source">.*<pre.*>.*<code.*language-.*># Fenced Code Block 2')

// Our third code block is indented, and it shows the same way
assert content =~ '<div class="source">.*<pre.*>.*<code.*>// Indented Code Block'

// Then we have inline code, which must be in simple <code>
assert content =~ 'inline code: <code>System.out.println'

// The last one is inline "fenced" code block which must be in simple <code>
assert content =~ 'And what about <code>System.out.println'
69 changes: 69 additions & 0 deletions doxia-modules/doxia-module-markdown/src/it/general/pom.xml
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.doxia</groupId>
<artifactId>it</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<description>Project Description</description>

<build>
<plugins>

<!-- site -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
<configuration>
<generateReports>false</generateReports>
<generateProjectInfo>false</generateProjectInfo>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-core</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-module-xhtml</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</dependency>
</dependencies>

</plugin>

</plugins>
</build>

</project>
@@ -0,0 +1,5 @@
# General Integration Tests for Doxia Markdown Module

Each page is dedicated to one specific feature of the Doxia Markdown Module.

Everything is tested in **verify.groovy**.
@@ -0,0 +1,11 @@
Author: Bertrand 'Yours, Truly' Martin
Title: Title from Header
Keywords: smile,😉,utf-8
Empty:

Weird : Spacing


# Title from Title

description: This description must not be included in the header

0 comments on commit b55285c

Please sign in to comment.