diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java b/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java index 12f12c4f..fdf63efe 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java @@ -638,7 +638,13 @@ String[] convertFiles(Collection asciidoctorFiles, * Unregister all registered extensions. */ void unregisterAllExtensions(); - + + /** + * Unregisters the extension represented by the given registration name. + * @param registrationName + */ + void unregisterExtension(String registrationName); + /** * This method frees all resources consumed by asciidoctorJ module. Keep in mind that if this method is called, instance becomes unusable and you should create another instance. */ diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/JavaExtensionRegistry.java b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/JavaExtensionRegistry.java index 2b969ae4..e3f7340b 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/JavaExtensionRegistry.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/JavaExtensionRegistry.java @@ -22,6 +22,13 @@ public void docinfoProcessor(Class docInfoProcessor) this.asciidoctorModule.docinfo_processor(RubyUtils.toRubyClass(rubyRuntime, docInfoProcessor)); } + public void docinfoProcessor(Class docInfoProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, docInfoProcessor); + this.asciidoctorModule.docinfo_processor(RubyUtils.toRubyClass(rubyRuntime, docInfoProcessor), registrationName); + } + public void docinfoProcessor(DocinfoProcessor docInfoProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -29,6 +36,13 @@ public void docinfoProcessor(DocinfoProcessor docInfoProcessor) { this.asciidoctorModule.docinfo_processor(docInfoProcessor); } + public void docinfoProcessor(DocinfoProcessor docInfoProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, docInfoProcessor.getClass()); + this.asciidoctorModule.docinfo_processor(docInfoProcessor, registrationName); + } + public void docinfoProcessor(String docInfoProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -36,6 +50,13 @@ public void docinfoProcessor(String docInfoProcessor) { this.asciidoctorModule.docinfo_processor(getClassName(docInfoProcessor)); } + public void docinfoProcessor(String docInfoProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, docInfoProcessor); + this.asciidoctorModule.docinfo_processor(getClassName(docInfoProcessor), registrationName); + } + public void preprocessor(Class preprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -43,6 +64,13 @@ public void preprocessor(Class preprocessor) { this.asciidoctorModule.preprocessor(RubyUtils.toRubyClass(rubyRuntime, preprocessor)); } + public void preprocessor(Class preprocessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, preprocessor); + this.asciidoctorModule.preprocessor(RubyUtils.toRubyClass(rubyRuntime, preprocessor), registrationName); + } + public void preprocessor(Preprocessor preprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -50,6 +78,13 @@ public void preprocessor(Preprocessor preprocessor) { this.asciidoctorModule.preprocessor(preprocessor); } + public void preprocessor(Preprocessor preprocessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, preprocessor.getClass()); + this.asciidoctorModule.preprocessor(preprocessor, registrationName); + } + public void preprocessor(String preprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -57,6 +92,13 @@ public void preprocessor(String preprocessor) { this.asciidoctorModule.preprocessor(getClassName(preprocessor)); } + public void preprocessor(String preprocessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, preprocessor); + this.asciidoctorModule.preprocessor(getClassName(preprocessor), registrationName); + } + public void postprocessor(String postprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -64,6 +106,13 @@ public void postprocessor(String postprocessor) { this.asciidoctorModule.postprocessor(getClassName(postprocessor)); } + public void postprocessor(String postprocessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, postprocessor); + this.asciidoctorModule.postprocessor(getClassName(postprocessor), registrationName); + } + public void postprocessor(Class postprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -71,6 +120,13 @@ public void postprocessor(Class postprocessor) { this.asciidoctorModule.postprocessor(RubyUtils.toRubyClass(rubyRuntime, postprocessor)); } + public void postprocessor(Class postprocessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, postprocessor); + this.asciidoctorModule.postprocessor(RubyUtils.toRubyClass(rubyRuntime, postprocessor), registrationName); + } + public void postprocessor(Postprocessor postprocesor) { // this may change in future to external class to deal with dynamic // imports @@ -78,6 +134,13 @@ public void postprocessor(Postprocessor postprocesor) { this.asciidoctorModule.postprocessor(postprocesor); } + public void postprocessor(Postprocessor postprocesor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, postprocesor.getClass()); + this.asciidoctorModule.postprocessor(postprocesor, registrationName); + } + public void includeProcessor(String includeProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -85,6 +148,13 @@ public void includeProcessor(String includeProcessor) { this.asciidoctorModule.include_processor(getClassName(includeProcessor)); } + public void includeProcessor(String includeProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, includeProcessor); + this.asciidoctorModule.include_processor(getClassName(includeProcessor), registrationName); + } + public void includeProcessor( Class includeProcessor) { // this may change in future to external class to deal with dynamic @@ -93,17 +163,36 @@ public void includeProcessor( this.asciidoctorModule.include_processor(RubyUtils.toRubyClass(rubyRuntime, includeProcessor)); } + public void includeProcessor( + Class includeProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, includeProcessor); + this.asciidoctorModule.include_processor(RubyUtils.toRubyClass(rubyRuntime, includeProcessor), registrationName); + } + public void includeProcessor(IncludeProcessor includeProcessor) { String importLine = getImportLine(includeProcessor.getClass()); javaImport(rubyRuntime, importLine); this.asciidoctorModule.include_processor(includeProcessor); } + public void includeProcessor(IncludeProcessor includeProcessor, String registrationName) { + String importLine = getImportLine(includeProcessor.getClass()); + javaImport(rubyRuntime, importLine); + this.asciidoctorModule.include_processor(includeProcessor, registrationName); + } + public void treeprocessor(Treeprocessor treeprocessor) { javaImport(rubyRuntime, treeprocessor.getClass()); this.asciidoctorModule.treeprocessor(treeprocessor); } + public void treeprocessor(Treeprocessor treeprocessor, String registrationName) { + javaImport(rubyRuntime, treeprocessor.getClass()); + this.asciidoctorModule.treeprocessor(treeprocessor, registrationName); + } + public void treeprocessor(Class treeProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -111,6 +200,13 @@ public void treeprocessor(Class treeProcessor) { this.asciidoctorModule.treeprocessor(RubyUtils.toRubyClass(rubyRuntime, treeProcessor)); } + public void treeprocessor(Class treeProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, treeProcessor); + this.asciidoctorModule.treeprocessor(RubyUtils.toRubyClass(rubyRuntime, treeProcessor), registrationName); + } + public void treeprocessor(String treeProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -118,6 +214,13 @@ public void treeprocessor(String treeProcessor) { this.asciidoctorModule.treeprocessor(getClassName(treeProcessor)); } + public void treeprocessor(String treeProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, treeProcessor); + this.asciidoctorModule.treeprocessor(getClassName(treeProcessor), registrationName); + } + public void block(String blockName, String blockProcessor) { // this may change in future to external class to deal with dynamic @@ -129,6 +232,17 @@ public void block(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void block(String blockName, + String blockProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, blockProcessor); + + this.asciidoctorModule.block_processor( + getClassName(blockProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + public void block(String blockName, Class blockProcessor) { // this may change in future to external class to deal with dynamic @@ -140,10 +254,25 @@ public void block(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void block(String blockName, + Class blockProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, blockProcessor); + + this.asciidoctorModule.block_processor( + RubyUtils.toRubyClass(rubyRuntime, blockProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + public void block(BlockProcessor blockProcessor) { block(blockProcessor.getName(), blockProcessor); } + public void block(BlockProcessor blockProcessor, String registrationName) { + block(blockProcessor.getName(), blockProcessor, registrationName); + } + public void block(String blockName, BlockProcessor blockProcessor) { // this may change in future to external class to deal with dynamic @@ -155,6 +284,17 @@ public void block(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void block(String blockName, + BlockProcessor blockProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, blockProcessor.getClass()); + + this.asciidoctorModule.block_processor( + blockProcessor, + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + public void blockMacro(String blockName, Class blockMacroProcessor) { // this may change in future to external class to deal with dynamic @@ -165,6 +305,16 @@ public void blockMacro(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void blockMacro(String blockName, + Class blockMacroProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, blockMacroProcessor); + this.asciidoctorModule.block_macro( + blockMacroProcessor.getSimpleName(), + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + public void blockMacro(String blockName, String blockMacroProcessor) { // this may change in future to external class to deal with dynamic @@ -175,6 +325,16 @@ public void blockMacro(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void blockMacro(String blockName, + String blockMacroProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, blockMacroProcessor); + this.asciidoctorModule.block_macro( + getClassName(blockMacroProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + public void blockMacro(BlockMacroProcessor blockMacroProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -184,6 +344,15 @@ public void blockMacro(BlockMacroProcessor blockMacroProcessor) { RubyUtils.toSymbol(rubyRuntime, blockMacroProcessor.getName())); } + public void blockMacro(BlockMacroProcessor blockMacroProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, blockMacroProcessor.getClass()); + this.asciidoctorModule.block_macro( + blockMacroProcessor, + RubyUtils.toSymbol(rubyRuntime, blockMacroProcessor.getName()), registrationName); + } + public void inlineMacro(InlineMacroProcessor inlineMacroProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -194,6 +363,16 @@ public void inlineMacro(InlineMacroProcessor inlineMacroProcessor) { RubyUtils.toSymbol(rubyRuntime, inlineMacroProcessor.getName())); } + public void inlineMacro(InlineMacroProcessor inlineMacroProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, inlineMacroProcessor.getClass()); + + this.asciidoctorModule.inline_macro( + inlineMacroProcessor, + RubyUtils.toSymbol(rubyRuntime, inlineMacroProcessor.getName()), registrationName); + } + public void inlineMacro(String blockName, Class inlineMacroProcessor) { // this may change in future to external class to deal with dynamic @@ -205,6 +384,17 @@ public void inlineMacro(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void inlineMacro(String blockName, + Class inlineMacroProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, inlineMacroProcessor); + + this.asciidoctorModule.inline_macro( + RubyUtils.toRubyClass(rubyRuntime, inlineMacroProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + public void inlineMacro(String blockName, String inlineMacroProcessor) { // this may change in future to external class to deal with dynamic imports javaImport(this.rubyRuntime, inlineMacroProcessor); @@ -214,6 +404,15 @@ public void inlineMacro(String blockName, String inlineMacroProcessor) { RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void inlineMacro(String blockName, String inlineMacroProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic imports + javaImport(this.rubyRuntime, inlineMacroProcessor); + + this.asciidoctorModule.inline_macro( + getClassName(inlineMacroProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + private void javaImport(Ruby ruby, Class clazz) { ruby.evalScriptlet(String.format("java_import '%s'", getImportLine(clazz))); } diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/RubyExtensionRegistry.java b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/RubyExtensionRegistry.java index 1b429ca5..e7c6ee72 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/RubyExtensionRegistry.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/RubyExtensionRegistry.java @@ -33,8 +33,18 @@ public RubyExtensionRegistry preprocessor(String preprocessor) { return this; } - public RubyExtensionRegistry postprocessor(String postprocesor) { - this.asciidoctorModule.postprocessor(postprocesor); + public RubyExtensionRegistry preprocessor(String preprocessor, String registrationName) { + this.asciidoctorModule.preprocessor(preprocessor, registrationName); + return this; + } + + public RubyExtensionRegistry postprocessor(String postprocessor) { + this.asciidoctorModule.postprocessor(postprocessor); + return this; + } + + public RubyExtensionRegistry postprocessor(String postprocessor, String registrationName) { + this.asciidoctorModule.postprocessor(postprocessor, registrationName); return this; } @@ -43,22 +53,43 @@ public RubyExtensionRegistry docinfoProcessor(String docinfoProcessor) { return this; } + public RubyExtensionRegistry docinfoProcessor(String docinfoProcessor, String registrationName) { + this.asciidoctorModule.docinfo_processor(docinfoProcessor, registrationName); + return this; + } + public RubyExtensionRegistry includeProcessor(String includeProcessor) { this.asciidoctorModule.include_processor(includeProcessor); return this; } + public RubyExtensionRegistry includeProcessor(String includeProcessor, String registrationName) { + this.asciidoctorModule.include_processor(includeProcessor, registrationName); + return this; + } + public RubyExtensionRegistry treeprocessor(String treeProcessor) { this.asciidoctorModule.treeprocessor(treeProcessor); return this; } + public RubyExtensionRegistry treeprocessor(String treeProcessor, String registrationName) { + this.asciidoctorModule.treeprocessor(treeProcessor, registrationName); + return this; + } + public RubyExtensionRegistry block(String blockName, String blockProcessor) { this.asciidoctorModule.block_processor( blockProcessor, RubyUtils.toSymbol(rubyRuntime, blockName)); return this; } + public RubyExtensionRegistry block(String blockName, String blockProcessor, String registrationName) { + this.asciidoctorModule.block_processor( + blockProcessor, RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + return this; + } + public RubyExtensionRegistry blockMacro(String blockName, String blockMacroProcessor) { this.asciidoctorModule.block_macro( @@ -66,6 +97,13 @@ public RubyExtensionRegistry blockMacro(String blockName, String blockMacroProce return this; } + public RubyExtensionRegistry blockMacro(String blockName, String blockMacroProcessor, String registrationName) { + + this.asciidoctorModule.block_macro( + blockMacroProcessor, RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + return this; + } + public RubyExtensionRegistry inlineMacro(String blockName, String inlineMacroProcessor) { this.asciidoctorModule.inline_macro( @@ -73,4 +111,11 @@ public RubyExtensionRegistry inlineMacro(String blockName, String inlineMacroPro return this; } + public RubyExtensionRegistry inlineMacro(String blockName, String inlineMacroProcessor, String registrationName) { + + this.asciidoctorModule.inline_macro( + inlineMacroProcessor, RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + return this; + } + } \ No newline at end of file diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/AsciidoctorModule.java b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/AsciidoctorModule.java index 7aa01e41..1f08d7ce 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/AsciidoctorModule.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/AsciidoctorModule.java @@ -13,38 +13,63 @@ public interface AsciidoctorModule { void preprocessor(String preprocessorClassName); + void preprocessor(String preprocessorClassName, String registrationName); void preprocessor(RubyClass preprocessorClassName); - void preprocessor(Preprocessor preprocessor); - + void preprocessor(RubyClass preprocessorClassName, String registrationName); + void preprocessor(Preprocessor preprocessor); + void preprocessor(Preprocessor preprocessor, String registrationName); + void postprocessor(String postprocessorClassName); + void postprocessor(String postprocessorClassName, String registrationName); void postprocessor(RubyClass postprocessorClassName); + void postprocessor(RubyClass postprocessorClassName, String registrationName); void postprocessor(Postprocessor postprocessor); - + void postprocessor(Postprocessor postprocessor, String registrationName); + void treeprocessor(String treeprocessor); + void treeprocessor(String treeprocessor, String registrationName); void treeprocessor(RubyClass treeprocessorClassName); + void treeprocessor(RubyClass treeprocessorClassName, String registrationName); void treeprocessor(Treeprocessor treeprocessorClassName); - + void treeprocessor(Treeprocessor treeprocessorClassName, String registrationName); + void include_processor(String includeProcessorClassName); + void include_processor(String includeProcessorClassName, String registrationName); void include_processor(RubyClass includeProcessorClassName); + void include_processor(RubyClass includeProcessorClassName, String registrationName); void include_processor(IncludeProcessor includeProcessor); - + void include_processor(IncludeProcessor includeProcessor, String registrationName); + void block_processor(String blockClassName, Object blockName); + void block_processor(String blockClassName, Object blockName, String registrationName); void block_processor(RubyClass blockClass, Object blockName); + void block_processor(RubyClass blockClass, Object blockName, String registrationName); void block_processor(BlockProcessor blockInstance, Object blockName); - + void block_processor(BlockProcessor blockInstance, Object blockName, String registrationName); + void block_macro(String blockMacroClassName, Object blockName); + void block_macro(String blockMacroClassName, Object blockName, String registrationName); void block_macro(Class blockMacroClass, Object blockName); + void block_macro(Class blockMacroClass, Object blockName, String registrationName); void block_macro(BlockMacroProcessor blockMacroInstance, Object blockName); - + void block_macro(BlockMacroProcessor blockMacroInstance, Object blockName, String registrationName); + void inline_macro(String blockClassName, Object blockSymbol); + void inline_macro(String blockClassName, Object blockSymbol, String registrationName); void inline_macro(RubyClass blockClassName, Object blockSymbol); + void inline_macro(RubyClass blockClassName, Object blockSymbol, String registrationName); void inline_macro(InlineMacroProcessor blockClassName, Object blockSymbol); - + void inline_macro(InlineMacroProcessor blockClassName, Object blockSymbol, String registrationName); + void docinfo_processor(String docInfoClassName); + void docinfo_processor(String docInfoClassName, String registrationName); void docinfo_processor(RubyClass docInfoClassName); + void docinfo_processor(RubyClass docInfoClassName, String registrationName); void docinfo_processor(DocinfoProcessor docInfoClassName); - + void docinfo_processor(DocinfoProcessor docInfoClassName, String registrationName); + void unregister_all_extensions(); + void unregister_extension(String registrationName); Object convert(String content, Map options); Object convertFile(String filename, Map options); diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java index 315486b7..ed663bc1 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java @@ -497,6 +497,11 @@ public void unregisterAllExtensions() { this.asciidoctorModule.unregister_all_extensions(); } + @Override + public void unregisterExtension(String registrationName) { + this.asciidoctorModule.unregister_extension(registrationName); + } + @Override public void shutdown() { this.rubyRuntime.tearDown(); diff --git a/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb b/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb index da34f73b..78640d92 100644 --- a/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb +++ b/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb @@ -4,7 +4,9 @@ module Extensions include_package 'org.asciidoctor.extension' # Treeprocessor was renamed in to TreeProcessor in https://github.com/asciidoctor/asciidoctor/commit/f1dd816ade9db457b899581841e4cf7b788aa26d # This is necessary to run against both Asciidoctor 1.5.5 and 1.5.6 - TreeProcessor = Treeprocessor + if !defined? TreeProcessor + TreeProcessor = Treeprocessor + end end end @@ -19,50 +21,54 @@ def unregister_all_extensions() Asciidoctor::Extensions.unregister_all end - def docinfo_processor(extensionName) - Asciidoctor::Extensions.register do + def unregister_extension name + Asciidoctor::Extensions.unregister name + end + + def docinfo_processor(extensionName, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do docinfo_processor extensionName end end - def treeprocessor(extensionName) - Asciidoctor::Extensions.register do + def treeprocessor(extensionName, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do treeprocessor extensionName end end - def include_processor(extensionName) - Asciidoctor::Extensions.register do + def include_processor(extensionName, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do include_processor extensionName end end - def preprocessor(extensionName) - Asciidoctor::Extensions.register do + def preprocessor(extensionName, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do preprocessor extensionName end end - def postprocessor(extensionName) - Asciidoctor::Extensions.register do + def postprocessor(extensionName, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do postprocessor extensionName end end - def block_processor(extensionName, blockSymbol) - Asciidoctor::Extensions.register do + def block_processor(extensionName, blockSymbol, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do block extensionName, blockSymbol end end - def block_macro(extensionName, blockSymbol) - Asciidoctor::Extensions.register do + def block_macro(extensionName, blockSymbol, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do block_macro extensionName, blockSymbol end end - def inline_macro(extensionName, blockSymbol) - Asciidoctor::Extensions.register do + def inline_macro(extensionName, blockSymbol, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do inline_macro extensionName, blockSymbol end end diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java index 06acc415..08660db1 100644 --- a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import org.asciidoctor.Asciidoctor; import org.asciidoctor.AttributesBuilder; @@ -700,4 +701,69 @@ public void a_block_processor_instance_should_be_executed_when_registered_block_ } + @Test + public void should_unregister_postprocessor() throws IOException { + + // Given: A registered Postprocessor + JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); + final String registrationName = UUID.randomUUID().toString(); + javaExtensionRegistry.postprocessor(CustomFooterPostProcessor.class, registrationName); + + // When: I render a document + Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html")) + .safe(SafeMode.UNSAFE).get(); + + asciidoctor.renderFile(classpath.getResource("rendersample.asciidoc"), options); + + // Then: it is invoked + File renderedFile = new File(testFolder.getRoot(), "rendersample.html"); + org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8"); + Element footer = doc.getElementById("footer-text"); + assertThat(footer.text(), containsString("Copyright Acme, Inc.")); + + // When: I unregister the Postprocessor and render again with the same Asciidoctor instance + asciidoctor.unregisterExtension(registrationName); + + Options options2 = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample2.html")) + .safe(SafeMode.UNSAFE).get(); + asciidoctor.renderFile(classpath.getResource("rendersample.asciidoc"), options2); + File renderedFile2 = new File(testFolder.getRoot(), "rendersample2.html"); + org.jsoup.nodes.Document doc2 = Jsoup.parse(renderedFile2, "UTF-8"); + + Element footer2 = doc2.getElementById("footer-text"); + assertThat(footer2.text(), not(containsString("Copyright Acme, Inc."))); + } + + @Test + public void should_unregister_block_processor() + throws IOException { + + JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); + final String registrationName = UUID.randomUUID().toString(); + + Map config = new HashMap(); + config.put("contexts", Arrays.asList(":paragraph")); + config.put("content_model", ":simple"); + YellBlock yellBlock = new YellBlock("yell", config); + javaExtensionRegistry.block(yellBlock, registrationName); + String content = asciidoctor.renderFile( + classpath.getResource("sample-with-yell-block.ad"), + options().toFile(false).get()); + Document doc = Jsoup.parse(content, "UTF-8"); + Elements elements = doc.getElementsByClass("paragraph"); + assertThat(elements.size(), is(1)); + assertThat(elements.get(0).text(), is("THE TIME IS NOW. GET A MOVE ON.")); + + asciidoctor.unregisterExtension(registrationName); + String contentWithoutBlock = asciidoctor.renderFile( + classpath.getResource("sample-with-yell-block.ad"), + options().toFile(false).get()); + Document docWithoutBlock = Jsoup.parse(contentWithoutBlock, "UTF-8"); + Elements elementsWithoutBlock = docWithoutBlock.getElementsByClass("paragraph"); + assertThat(elementsWithoutBlock.size(), is(1)); + assertThat(elementsWithoutBlock.get(0).text(), not(is("THE TIME IS NOW. GET A MOVE ON."))); + + } + + } diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java index 865dd89b..e9c677f4 100644 --- a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java @@ -2,6 +2,7 @@ import static org.asciidoctor.OptionsBuilder.options; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertThat; import org.asciidoctor.Asciidoctor; @@ -13,6 +14,8 @@ import org.junit.Rule; import org.junit.Test; +import java.util.UUID; + public class WhenRubyExtensionIsRegistered { @Rule @@ -37,4 +40,34 @@ public void ruby_extension_should_be_registered() { } + @Test + public void ruby_extension_should_be_unregistered() { + + RubyExtensionRegistry rubyExtensionRegistry = this.asciidoctor.rubyExtensionRegistry(); + String registrationName = UUID.randomUUID().toString(); + + rubyExtensionRegistry.loadClass(Class.class.getResourceAsStream("/YellRubyBlock.rb")).block("rubyyell", "YellRubyBlock", registrationName); + + String content = asciidoctor.renderFile( + classpath.getResource("sample-with-ruby-yell-block.ad"), + options().toFile(false).get()); + + Document doc = Jsoup.parse(content, "UTF-8"); + Elements elements = doc.getElementsByClass("paragraph"); + assertThat(elements.size(), is(2)); + assertThat(elements.get(1).text(), is("THE TIME IS NOW! GET A MOVE ON!")); + + asciidoctor.unregisterExtension(registrationName); + + String contentWithoutBlock = asciidoctor.renderFile( + classpath.getResource("sample-with-ruby-yell-block.ad"), + options().toFile(false).get()); + + Document docWithoutBlock = Jsoup.parse(contentWithoutBlock, "UTF-8"); + Elements elementsWithoutBlock = docWithoutBlock.getElementsByClass("paragraph"); + assertThat(elementsWithoutBlock.size(), is(2)); + assertThat(elementsWithoutBlock.get(1).text(), not(is("THE TIME IS NOW! GET A MOVE ON!"))); + + } + } diff --git a/build.gradle b/build.gradle index fc48a6ae..0be572f2 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ ext { xmlMatchersVersion = '1.0-RC1' // gem versions - asciidoctorGemVersion = project.hasProperty('asciidoctorGemVersion') ? project.asciidoctorGemVersion : '1.5.5' + asciidoctorGemVersion = project.hasProperty('asciidoctorGemVersion') ? project.asciidoctorGemVersion : '1.5.6' asciidoctorEpub3GemVersion = project(':asciidoctorj-epub3').version.replace('-', '.') asciidoctorDiagramGemVersion = project(':asciidoctorj-diagram').version.replace('-', '.')