public static void generatePdf(final File from, final File targetBase) throws IOException { final Path sourceBase = from.toPath(); final Asciidoctor asciidoctor = Asciidoctor.Factory.create(); final ExecutorService pool = Executors.newFixedThreadPool(16); Files.walkFileTree(sourceBase, new SimpleFileVisitor<Path>() {
final Asciidoctor secondInstance = Asciidoctor.Factory.create();
final Asciidoctor asciidoctor = Asciidoctor.Factory.create(singletonList(rubyExtPath)); asciidoctor.createGroup() .requireRubyLibrary("view-result-docinfoprocessor.rb")
final Asciidoctor asciidoctor = Asciidoctor.Factory.create(singletonList(rubyExtPath)); asciidoctor.rubyExtensionRegistry() .requireLibrary("view-result-docinfoprocessor.rb")
final Asciidoctor asciidoctor = Asciidoctor.Factory.create(singletonList(rubyExtPath)); asciidoctor.rubyExtensionRegistry() .requireLibrary("front-matter-preprocessor.rb")
private void createDocs() { String version = "2.0.0-SNAPSHOT"; Asciidoctor asciidoctor = create(); try { File file = new File("sqlg-doc/docs/" + version + "/sqlg.adoc"); File html = new File("sqlg-doc/docs/" + version + "/index.html"); Attributes attributes = new Attributes(); attributes.setBackend("html5"); attributes.setStyleSheetName("asciidoctor-default.css"); attributes.setDocType("book"); attributes.setSourceHighlighter("highlightjs"); Map<String, Object> options = OptionsBuilder.options() .attributes(attributes) .toFile(new File(html.getPath())) .headerFooter(true) .safe(SafeMode.SERVER) .asMap(); options.put("location", ":footer"); Docinfo docinfo = new Docinfo(options); asciidoctor.javaExtensionRegistry().docinfoProcessor(docinfo); asciidoctor.convertFile( file, options ); } catch (Exception e) { throw new RuntimeException(e); } }
Thread.currentThread().setContextClassLoader(tccl); Asciidoctor asciidoctor = Asciidoctor.Factory.create();
@Test public void ruby_treeprocessor_should_be_registered() { final String rubyExtPath = classpath.getResource("ruby-extensions").getAbsolutePath(); final Asciidoctor asciidoctor = Asciidoctor.Factory.create(singletonList(rubyExtPath)); asciidoctor.rubyExtensionRegistry() .requireLibrary("shell-session-tree-processor.rb") .treeprocessor("ShellSessionTreeProcessor"); String content = asciidoctor.convert( " $ echo \"Hello, World!\"\n" + " > Hello, World!\n" + "\n" + " $ gem install asciidoctor", options().toFile(false).get()); final Document document = Jsoup.parse(content); final TextNode commandElement = document.getElementsByClass("command").get(0).textNodes().get(0); assertThat(commandElement.getWholeText(), is("echo \"Hello, World!\"")); final TextNode commandElement2 = document.getElementsByClass("command").get(1).textNodes().get(0); assertThat(commandElement2.getWholeText(), is("gem install asciidoctor")); }
private List<InputStream> convertToInputStreams(List<File> source) throws IOException { List<InputStream> inputStreams = new ArrayList<>(); Asciidoctor asciidoctor = Factory.create(); ExtensionGroup group = asciidoctor.createGroup(); Preprocessor preprocessor = new Preprocessor(); group.preprocessor(preprocessor); Options options = new Options(); options.setToFile(false); options.setSafe(SafeMode.UNSAFE); group.register(); for (File file : source) { inputStreams.add(processSingleFile(file, asciidoctor, group, preprocessor, options)); } return inputStreams; }
@Override public String convertAsciiDocToXHtml(final String asciiDoc) { LOG.info("Converting AsciiDoc to XHTML5..."); final Asciidoctor asciidoctor = create(); final Map<String, Object> attributes = AttributesBuilder.attributes() .unsetStyleSheet() .tableOfContents(Placement.TOP) .asMap(); final Map<String, Object> options = OptionsBuilder.options() .attributes(attributes) .backend("xhtml5") .asMap(); LOG.info("XHTML5 Conversion Complete!"); return asciidoctor.render(asciiDoc, options); }
public AsciidoctorRenderer(DocletOptions docletOptions, DocErrorReporter errorReporter) { this(docletOptions, errorReporter, OutputTemplates.create(errorReporter), create(docletOptions.gemPath())); }
public static void compileCourse(Path srcPath, String courseName, Path destPath, Path libSrcPath, PathConfig pcfg, TutorCommandExecutor executor) throws IOException, NoSuchRascalFunction, URISyntaxException { compileCourse(create(), srcPath, courseName, destPath, libSrcPath, pcfg, executor); }
static void runAsciiDocter(Path srcPath, String courseName, Path destPath, PrintWriter err) throws IOException { runAsciiDoctor(create(), srcPath, courseName, destPath, err); }
private Asciidoctor getAsciidoctor() { return asciidoctor == null ? asciidoctor = Asciidoctor.Factory.create() : asciidoctor; }
@Test public void ruby_postprocessor_should_be_registered() { final String rubyExtPath = classpath.getResource("ruby-extensions").getAbsolutePath(); final Asciidoctor asciidoctor = Asciidoctor.Factory.create(singletonList(rubyExtPath)); asciidoctor.createGroup() .requireRubyLibrary("xml-entity-postprocessor.rb") .rubyPostprocessor("XmlEntityPostprocessor") .register(); String content = asciidoctor.convert( "Read §2 and it'll all be clear.", options().toFile(false).get()); System.out.println(content); assertThat(content, containsString("Read §2 and it'll all be clear.")); }
@PostConstruct public void init() { doctor = Asciidoctor.Factory.create(); }
@Test public void should_have_gempath_in_ruby_env_when_created_with_gempath() { // Given: Our environment is polluted (Cannot set these env vars here, so just check that gradle has set them correctly) final String gemPath = "/another/path"; assertThat(System.getenv("GEM_PATH"), notNullValue()); assertThat(System.getenv("GEM_HOME"), notNullValue()); // When: A new Asciidoctor instance is created passing in a null GEM_PATH Asciidoctor asciidoctor = Asciidoctor.Factory.create(gemPath); // Then: The org.jruby.JRuby instance does not see this variable Ruby rubyRuntime = JRubyRuntimeContext.get(asciidoctor); RubyString rubyGemPath = rubyRuntime.newString(gemPath); assertThat(rubyRuntime.evalScriptlet("ENV['GEM_PATH']"), is((Object) rubyGemPath)); assertThat(rubyRuntime.evalScriptlet("ENV['GEM_HOME']"), is((Object) rubyGemPath)); }
@Override public void init() throws ServletException { asciidoctor = Asciidoctor.Factory.create(); }