@Test public void useMacroWithoutSnippetAttributeAddsAllSnippets() throws Exception { String result = this.asciidoctor.convert("operation::some-operation[]", this.options); assertThat(result).isEqualTo(getExpectedContentFromFile("all-snippets")); }
private void processAsciiDoc(ParserContext context) { Options options = getAsciiDocOptionsAndAttributes(context); final Asciidoctor asciidoctor = getEngine(options); context.setBody(asciidoctor.render(context.getBody(), options)); }
@Override public void close() { if (asciidoctor != null) { asciidoctor.shutdown(); asciidoctor = null; } }
@Override public void register(Asciidoctor asciidoctor) { asciidoctor.javaExtensionRegistry() .preprocessor(new DefaultAttributesPreprocessor()); asciidoctor.rubyExtensionRegistry() .loadClass(RestDocsExtensionRegistry.class .getResourceAsStream("/extensions/operation_block_macro.rb")) .blockMacro("operation", "OperationBlockMacro"); }
/** * Return the pre-configured {@link Asciidoctor} instance. * * @return The {@link Asciidoctor} instance. */ public static Asciidoctor getAsciidoctor() { Asciidoctor asciidoctor = Asciidoctor.Factory.create(); asciidoctor.requireLibrary(ASCIIDOCTOR_DIAGRAM); LOGGER.debug("Loaded Asciidoctor " + asciidoctor.asciidoctorVersion()); return asciidoctor; }
@Test public void a_block_processor_should_be_executed_when_registered_listing_block_is_found_in_document() throws IOException { this.asciidoctor.createGroup() .block("yell", YellStaticListingBlock.class) .register(); String content = asciidoctor.convertFile( classpath.getResource("sample-with-yell-listing-block.ad"), options().toFile(false).get()); org.jsoup.nodes.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.")); }
@Test public void testRegisterClassAsClassWithExplicitName() { final String explicitblockname = "anotherexplicitname"; asciidoctor.javaExtensionRegistry().inlineMacro(explicitblockname, AbstractTestProcessor.class); final String result = asciidoctor.convert(document(explicitblockname, "ExplicitClass"), OptionsBuilder.options()); check("Hello EXPLICIT CLASS", result); }
@Test public void a_preprocessor_instance_should_be_executed_before_document_is_rendered() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.preprocessor(new ChangeAttributeValuePreprocessor(new HashMap<>())); String content = asciidoctor.convertFile( classpath.getResource("changeattribute.adoc"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); assertThat(doc.getElementsByTag("p").first().text(), is("sample Alex")); }
asciidoctor.registerLogHandler(logHandler); String renderContent1 = secondInstance.convertFile(inputFile, options() .inPlace(true) String renderContent = asciidoctor.convertFile(inputFile, options() .inPlace(true)
File adocFile = FileUtil.saveFile(outputName, doc); Asciidoctor asciidoctor = Asciidoctor.Factory.create(); ExtensionGroup cukedoctorExtensionGroup = asciidoctor.createGroup(CUKEDOCTOR_EXTENSION_GROUP_NAME); if (attrs.getBackend().equalsIgnoreCase("pdf")) { cukedoctorExtensionGroup.unregister(); String aaaa = asciidoctor.convertFile(adocFile, ob.asMap()); asciidoctor.shutdown(); return doc;
@Test public void file_document_should_be_rendered_into_current_directory() throws FileNotFoundException, IOException, SAXException, ParserConfigurationException { File inputFile = classpath.getResource("rendersample.asciidoc"); String renderContent = asciidoctor.convertFile(inputFile, options() .inPlace(true).asMap()); File expectedFile = new File(inputFile.getParent(), "rendersample.html"); assertThat(expectedFile.exists(), is(true)); assertThat(renderContent, is(nullValue())); expectedFile.delete(); }
@Test public void a_extension_should_be_able_to_log() throws Exception { final List<LogRecord> logRecords = new ArrayList<>(); final LogHandler logHandler = new LogHandler() { @Override public void log(LogRecord logRecord) { logRecords.add(logRecord); } }; asciidoctor.registerLogHandler(logHandler); asciidoctor.javaExtensionRegistry().block(LoggingProcessor.class); String renderContent = asciidoctor.convert("= Test\n\n== Something different\n\n[big]\nHello World", options().option("sourcemap", "true").asMap()); assertEquals(1, logRecords.size()); assertThat(logRecords.get(0).getMessage(), is("Hello Log")); final Cursor cursor = logRecords.get(0).getCursor(); assertThat(cursor.getLineNumber(), is(3)); assertThat(renderContent, containsString("HELLO WORLD")); }
Asciidoctor asciidoctor = Asciidoctor.Factory.create(); asciidoctor.convertFile(adocFile, options); asciidoctor.shutdown(); LOGGER.info("Cucumber documentation generated at " + adocFile.getParent());
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { final String fileName = file.getFileName().toString(); if (fileName.endsWith(".adoc")) { pool.submit(() -> { final String path = sourceBase.relativize(file).toString(); final File target = new File(targetBase, path.substring(0, path.length() - "adoc".length()) + "pdf"); final File asFile = file.toFile(); final Map<String, Object> attributes = asciidoctor.readDocumentHeader(asFile).getAttributes(); // if we generate the PDF link we need to create the PDF excepted if it is expected to be manual if (attributes.containsKey("jbake-meecrowavepdf") && !attributes.containsKey("jbake-meecrowavepdf-manual")) { target.getParentFile().mkdirs(); asciidoctor.convertFile( asFile, options() //.baseDir(asFile.getParentFile()) .safe(UNSAFE) .backend("pdf") .attributes(AttributesBuilder.attributes() .attribute("source-highlighter", "coderay") .attribute("context_rootpath", "http://openwebbeans.apache.org/meecrowave")) .toFile(target).get()); System.out.println("Generated " + target); } }); } return super.visitFile(file, attrs); } });
asciidoctor.registerLogHandler(logHandler); String renderContent = asciidoctor.convertFile(inputFile, options() .inPlace(true) logRecords.clear(); asciidoctor.unregisterLogHandler(logHandler); asciidoctor.convertFile(inputFile, options() .inPlace(true)
Options options = getAsciiDocOptionsAndAttributes(context); final Asciidoctor asciidoctor = getEngine(options); DocumentHeader header = asciidoctor.readDocumentHeader(context.getFile()); Map<String, Object> documentModel = context.getDocumentModel(); if (header.getDocumentTitle() != null) {
if (requires.length != 0) { for (String require : requires) { engine.requireLibrary(require);
public void registerAllLogHandlers() { for (LogHandler logHandler: logHandlerServiceLoader) { asciidoctor.registerLogHandler(logHandler); } }
asciidoctor.requireLibraries(requires); final MemoryLogHandler memoryLogHandler = new MemoryLogHandler(outputToConsole, sourceDirectory, getLog()); if (!sourceFiles.isEmpty()) { asciidoctor.registerLogHandler(memoryLogHandler);
@Test public void a_preprocessor_instance_should_be_executed_before_document_is_rendered() { this.asciidoctor.createGroup() .preprocessor(new ChangeAttributeValuePreprocessor(new HashMap<String, Object>())) .register(); String content = asciidoctor.convertFile( classpath.getResource("changeattribute.adoc"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); assertThat(doc.getElementsByTag("p").first().text(), is("sample Alex")); }