protected void setAttributesOnBuilder(AttributesBuilder attributesBuilder) throws MojoExecutionException { if (sourceHighlighter != null) { attributesBuilder.sourceHighlighter(sourceHighlighter); } if (embedAssets) { attributesBuilder.linkCss(false); attributesBuilder.dataUri(true); } if (imagesDir != null) { attributesBuilder.imagesDir(imagesDir); } if ("skip".equals(attributeMissing) || "drop".equals(attributeMissing) || "drop-line".equals(attributeMissing)) { attributesBuilder.attributeMissing(attributeMissing); } else { throw new MojoExecutionException(attributeMissing + " is not valid. Must be one of 'skip', 'drop' or 'drop-line'"); } if ("drop".equals(attributeUndefined) || "drop-line".equals(attributeUndefined)) { attributesBuilder.attributeUndefined(attributeUndefined); } else { throw new MojoExecutionException(attributeUndefined + " is not valid. Must be one of 'drop' or 'drop-line'"); } AsciidoctorHelper.addAttributes(attributes, attributesBuilder); if (!attributesChain.isEmpty()) { getLog().info("Attributes: " + attributesChain); attributesBuilder.arguments(attributesChain); } }
@Test public void source_highlighter_attribute_should_add_required_javascript_libraries_as_highlighter() throws IOException { Attributes attributes = attributes().sourceHighlighter("prettify").get(); Options options = options().inPlace(false).safe(SafeMode.UNSAFE) .toDir(testFolder.getRoot()).attributes(attributes).get(); asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options); Document doc = Jsoup.parse(new File(testFolder.getRoot(), "rendersample.html"), "UTF-8"); Elements link = doc.select("link"); assertThat(link.get(1).attr("href"), containsString("prettify.min.css")); }
@Test public void not_coderay_gem_should_not_be_preloaded() { Map<String, Object> options = OptionsBuilder.options() .attributes(AttributesBuilder.attributes().sourceHighlighter("pygments").get()).asMap(); ((JRubyAsciidoctor) asciidoctor).rubyGemsPreloader.preloadRequiredLibraries(options); RubyBoolean evalScriptlet = (RubyBoolean) ((JRubyAsciidoctor) asciidoctor).rubyRuntime.evalScriptlet("require 'coderay'"); assertThat(evalScriptlet.isTrue(), is(true)); }
@Test public void coderay_gem_should_be_preloaded() { Map<String, Object> options = OptionsBuilder.options() .attributes(AttributesBuilder.attributes().sourceHighlighter("coderay").get()).asMap(); ((JRubyAsciidoctor) asciidoctor).rubyGemsPreloader.preloadRequiredLibraries(options); RubyBoolean evalScriptlet = (RubyBoolean) ((JRubyAsciidoctor) asciidoctor).rubyRuntime.evalScriptlet("require 'coderay'"); assertThat(evalScriptlet.isFalse(), is(true)); }