-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to allow extensions from non-"com." packages to be registered
Resolves #250, including test which fails without this fix
- Loading branch information
1 parent
88654d6
commit 7a14705
Showing
3 changed files
with
113 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...j-core/src/test/java/org/asciidoctor/internal/WhenLoadingExtensionFromUnusualPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.asciidoctor.internal; | ||
|
||
import org.asciidoctor.Asciidoctor; | ||
import org.asciidoctor.SafeMode; | ||
import org.asciidoctor.ast.AbstractBlock; | ||
import org.asciidoctor.ast.Block; | ||
import org.asciidoctor.extension.BlockMacroProcessor; | ||
import org.asciidoctor.extension.JavaExtensionRegistry; | ||
import org.asciidoctor.internal.JRubyAsciidoctor; | ||
import org.asciidoctor.util.ClasspathResources; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import unusual.extension.BoldifyPostProcessor; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
|
||
import static org.asciidoctor.OptionsBuilder.options; | ||
|
||
public class WhenLoadingExtensionFromUnusualPackage { | ||
|
||
@Rule | ||
public ClasspathResources classpath = new ClasspathResources(); | ||
|
||
private Asciidoctor asciidoctor = JRubyAsciidoctor.create(); | ||
|
||
@Test | ||
public void shouldAllowLoadingUsingInstance() { | ||
final JavaExtensionRegistry registry = asciidoctor.javaExtensionRegistry(); | ||
registry.postprocessor(new unusual.extension.BoldifyPostProcessor()); | ||
} | ||
|
||
@Test | ||
public void shouldAllowLoadingByClassName() { | ||
final JavaExtensionRegistry registry = asciidoctor.javaExtensionRegistry(); | ||
registry.postprocessor(BoldifyPostProcessor.class.getCanonicalName()); | ||
} | ||
|
||
@Test | ||
public void shouldAllowLoadingByClass() { | ||
final JavaExtensionRegistry registry = asciidoctor.javaExtensionRegistry(); | ||
registry.postprocessor(BoldifyPostProcessor.class); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
asciidoctorj-core/src/test/java/unusual/extension/BoldifyPostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package unusual.extension; | ||
|
||
import org.asciidoctor.ast.Document; | ||
import org.asciidoctor.extension.Postprocessor; | ||
|
||
/** | ||
* This processor is used only for checking we are able to load extensions from "unusual packages". | ||
* | ||
* @see org.asciidoctor.internal.WhenLoadingExtensionFromUnusualPackage | ||
* @see <a href="https://github.com/asciidoctor/asciidoctorj/issues/250">Issue #250</a> | ||
*/ | ||
public class BoldifyPostProcessor extends Postprocessor { | ||
@Override public String process(Document document, String output) { | ||
if (document.basebackend("html")) { | ||
return output.replaceAll("bold", "<b>bold</b>"); | ||
} else { | ||
return output; | ||
} | ||
} | ||
} |