org.asciidoctor.Options Java Examples

The following examples show how to use org.asciidoctor.Options. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Swagger2ToDocTest.java    From singleton with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void convertV2Doc() {
	Asciidoctor asciidoctor = create();
	Options options = new Options();
	options.setInPlace(true);
	options.setBackend("html5");
	options.setSafe(SafeMode.SAFE);
	options.setToDir(baseOutputDir + "/html5/v2");
	options.setMkDirs(true);
	options.setDocType("docbook");

	Map<String, Object> attributes = new HashMap<String, Object>();
	attributes.put("toc", "left");
	attributes.put("toclevels", "3");
	attributes.put("generated", "./generated/v2");
	options.setAttributes(attributes);

	asciidoctor.convertFile(new File(baseOutputDir + "/index.adoc"), options);
}
 
Example #2
Source File: AsciiDocViewEngine.java    From krazo with Apache License 2.0 6 votes vote down vote up
@Override
public void processView(ViewEngineContext context) throws ViewEngineException {
    Charset charset = resolveCharsetAndSetContentType(context);
    try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset);
         InputStream is = servletContext.getResourceAsStream(resolveView(context));
         InputStreamReader isr = new InputStreamReader(is, "UTF-8");
         BufferedReader reader = new BufferedReader(isr)) {

        Options options = new Options();
        options.setAttributes(new HashMap<>(context.getModels().asMap()));

        asciidoctor.convert(reader, writer, options);
    } catch (IOException e) {
        throw new ViewEngineException(e);
    }
}
 
Example #3
Source File: AsciidocConfluencePage.java    From confluence-publisher with Apache License 2.0 6 votes vote down vote up
public static AsciidocConfluencePage newAsciidocConfluencePage(AsciidocPage asciidocPage, Charset sourceEncoding, Path templatesDir, Path pageAssetsFolder, PageTitlePostProcessor pageTitlePostProcessor, Map<String, Object> userAttributes) {
    try {
        Path asciidocPagePath = asciidocPage.path();
        String asciidocContent = readIntoString(newInputStream(asciidocPagePath), sourceEncoding);

        Map<String, String> attachmentCollector = new HashMap<>();

        Options options = options(templatesDir, asciidocPagePath.getParent(), pageAssetsFolder, userAttributes);
        String pageContent = convertedContent(asciidocContent, options, asciidocPagePath, attachmentCollector, pageTitlePostProcessor, sourceEncoding);

        String pageTitle = pageTitle(asciidocContent, pageTitlePostProcessor);

        List<String> keywords = keywords(asciidocContent);

        return new AsciidocConfluencePage(pageTitle, pageContent, attachmentCollector, keywords);
    } catch (IOException e) {
        throw new RuntimeException("Could not create asciidoc confluence page", e);
    }
}
 
Example #4
Source File: AsciidocConfluencePage.java    From confluence-publisher with Apache License 2.0 6 votes vote down vote up
private static Options options(Path templatesFolder, Path baseFolder, Path generatedAssetsTargetFolder, Map<String, Object> userAttributes) {
    if (!exists(templatesFolder)) {
        throw new RuntimeException("templateDir folder does not exist");
    }

    if (!isDirectory(templatesFolder)) {
        throw new RuntimeException("templateDir folder is not a folder");
    }

    Map<String, Object> attributes = new HashMap<>(userAttributes);
    attributes.put("imagesoutdir", generatedAssetsTargetFolder.toString());
    attributes.put("outdir", generatedAssetsTargetFolder.toString());
    attributes.put("source-highlighter", "none");

    return OptionsBuilder.options()
            .backend("xhtml5")
            .safe(UNSAFE)
            .baseDir(baseFolder.toFile())
            .templateDirs(templatesFolder.toFile())
            .attributes(attributes)
            .get();
}
 
Example #5
Source File: AsciiDocViewEngine.java    From ozark with Apache License 2.0 6 votes vote down vote up
@Override
public void processView(ViewEngineContext context) throws ViewEngineException {
    Charset charset = resolveCharsetAndSetContentType(context);
    try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset);
         InputStream is = servletContext.getResourceAsStream(resolveView(context));
         InputStreamReader isr = new InputStreamReader(is, "UTF-8");
         BufferedReader reader = new BufferedReader(isr)) {

        Options options = new Options();
        options.setAttributes(new HashMap<>(context.getModels().asMap()));

        asciidoctor.convert(reader, writer, options);
    } catch (IOException e) {
        throw new ViewEngineException(e);
    }
}
 
Example #6
Source File: Swagger2ToDocTest.java    From singleton with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void convertV1Doc() {
	Asciidoctor asciidoctor = create();
	Options options = new Options();
	options.setInPlace(true);
	options.setBackend("html5");
	options.setSafe(SafeMode.SAFE);
	options.setToDir(baseOutputDir + "/html5/v1");
	options.setMkDirs(true);
	options.setDocType("docbook");

	Map<String, Object> attributes = new HashMap<String, Object>();
	attributes.put("toc", "left");
	attributes.put("toclevels", "3");
	attributes.put("generated", "./generated/v1");
	options.setAttributes(attributes);

	asciidoctor.convertFile(new File(baseOutputDir + "/index.adoc"), options);
}
 
Example #7
Source File: WhenJavaExtensionIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore
public void extensions_should_be_correctly_added_using_extension_registry() throws IOException {

    // To avoid registering the same extension over and over for all tests,
    // service is instantiated manually.
    new ArrowsAndBoxesExtension().register(asciidoctor);

    Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html"))
            .safe(SafeMode.UNSAFE).get();

    asciidoctor.convertFile(classpath.getResource("arrows-and-boxes-example.ad"), options);

    File renderedFile = new File(testFolder.getRoot(), "rendersample.html");
    org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8");

    Element arrowsJs = doc.select("script[src=http://www.headjump.de/javascripts/arrowsandboxes.js").first();
    assertThat(arrowsJs, is(notNullValue()));

    Element arrowsCss = doc.select("link[href=http://www.headjump.de/stylesheets/arrowsandboxes.css").first();
    assertThat(arrowsCss, is(notNullValue()));

    Element arrowsAndBoxes = doc.select("pre[class=arrows-and-boxes").first();
    assertThat(arrowsAndBoxes, is(notNullValue()));

}
 
Example #8
Source File: WhenJavaExtensionGroupIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void a_postprocessor_as_string_should_be_executed_after_document_is_rendered() throws IOException {

    this.asciidoctor.createGroup()
        .postprocessor("org.asciidoctor.extension.CustomFooterPostProcessor")
        .register();

    Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html"))
            .safe(SafeMode.UNSAFE).get();

    asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options);

    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."));
}
 
Example #9
Source File: WhenJavaExtensionGroupIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void a_postprocessor_should_be_executed_after_document_is_rendered() throws IOException {

    this.asciidoctor.createGroup()
        .postprocessor(CustomFooterPostProcessor.class)
        .register();

    Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html"))
            .safe(SafeMode.UNSAFE).get();

    asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options);

    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."));
}
 
Example #10
Source File: JRubyProcessor.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Override
public PhraseNode createPhraseNode(ContentNode parent, String context, List<String> text, Map<String, Object> attributes, Map<Object, Object> options) {

    Ruby rubyRuntime = JRubyRuntimeContext.get(parent);

    options.put(Options.ATTRIBUTES, attributes);

    RubyHash convertMapToRubyHashWithSymbols = RubyHashUtil.convertMapToRubyHashWithSymbolsIfNecessary(rubyRuntime,
            options);

    RubyArray rubyText = rubyRuntime.newArray();
    rubyText.addAll(text);

    IRubyObject[] parameters = {
            ((ContentNodeImpl) parent).getRubyObject(),
            RubyUtils.toSymbol(rubyRuntime, context),
            rubyText,
            convertMapToRubyHashWithSymbols};
    return (PhraseNode) NodeConverter.createASTNode(rubyRuntime, NodeConverter.NodeType.INLINE_CLASS, parameters);
}
 
Example #11
Source File: JRubyProcessor.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Override
public PhraseNode createPhraseNode(ContentNode parent, String context, String text, Map<String, Object> attributes, Map<String, Object> options) {

    Ruby rubyRuntime = JRubyRuntimeContext.get(parent);

    options.put(Options.ATTRIBUTES, RubyHashUtil.convertMapToRubyHashWithStrings(rubyRuntime, attributes));

    RubyHash convertedOptions = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);

    IRubyObject[] parameters = {
            ((ContentNodeImpl) parent).getRubyObject(),
            RubyUtils.toSymbol(rubyRuntime, context),
            text == null ? rubyRuntime.getNil() : rubyRuntime.newString(text),
            convertedOptions};
    return (PhraseNode) NodeConverter.createASTNode(rubyRuntime, NodeConverter.NodeType.INLINE_CLASS, parameters);
}
 
Example #12
Source File: WhenJavaExtensionGroupIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void a_postprocessor_instance_should_be_executed_after_document_is_rendered() throws IOException {

    this.asciidoctor.createGroup()
        .postprocessor(new CustomFooterPostProcessor(new HashMap<String, Object>()))
        .register();

    Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html"))
            .safe(SafeMode.UNSAFE).get();

    asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options);

    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."));
}
 
Example #13
Source File: WhenJavaExtensionGroupIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void should_unregister_all_current_registered_extensions() throws IOException {

    this.asciidoctor.createGroup()
        .postprocessor(CustomFooterPostProcessor.class)
        .register();

    Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html"))
            .safe(SafeMode.UNSAFE).get();

    asciidoctor.unregisterAllExtensions();
    asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options);

    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(), not(containsString("Copyright Acme, Inc.")));
}
 
Example #14
Source File: AsciidoctorEngine.java    From jbake with MIT License 5 votes vote down vote up
private Asciidoctor getEngine(Options options) {
    try {
        lock.readLock().lock();
        if (engine == null) {
            lock.readLock().unlock();
            try {
                lock.writeLock().lock();
                if (engine == null) {
                    LOGGER.info("Initializing Asciidoctor engine...");
                    if (options.map().containsKey(OPT_GEM_PATH)) {
                        engine = AsciidoctorJRuby.Factory.create(String.valueOf(options.map().get(OPT_GEM_PATH)));
                    } else {
                        engine = Asciidoctor.Factory.create();
                    }

                    if (options.map().containsKey(OPT_REQUIRES)) {
                        String[] requires = String.valueOf(options.map().get(OPT_REQUIRES)).split(",");
                        if (requires.length != 0) {
                            for (String require : requires) {
                                engine.requireLibrary(require);
                            }
                        }
                    }

                    LOGGER.info("Asciidoctor engine initialized.");
                }
            } finally {
                lock.readLock().lock();
                lock.writeLock().unlock();
            }
        }
    } finally {
        lock.readLock().unlock();
    }
    return engine;
}
 
Example #15
Source File: DefaultCssResolver.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private File getDestinationDirectory(File currentDirectory, Map<String, Object> options) {

        if ("".equals(options.get(Options.IN_PLACE))) {
            return currentDirectory;
        } else {

            if (options.containsKey(Options.TO_FILE)) {

                File toFile = new File((String) options.get(Options.TO_FILE));

                if (toFile.isAbsolute()) {
                    return toFile.getParentFile();
                } else {
                    if (options.containsKey(Options.TO_DIR)) {
                        File toDir = new File((String) options.get(Options.TO_DIR));
                        return new File(toDir, toFile.getParent());
                    } else {
                        return new File(currentDirectory, toFile.getParent());
                    }
                }

            } else {

                if (options.containsKey(Options.TO_DIR)) {
                    return new File((String) options.get(Options.TO_DIR));
                } else {
                    return currentDirectory;
                }
            }
        }
    }
 
Example #16
Source File: JRubyAsciidoctor.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T convertFile(File file, Map<String, Object> options, Class<T> expectedResult) {

    this.rubyGemsPreloader.preloadRequiredLibraries(options);

    logger.fine(String.join(" ", AsciidoctorUtils.toAsciidoctorCommand(options, file.getAbsolutePath())));

    String currentDirectory = rubyRuntime.getCurrentDirectory();

    if (options.containsKey(Options.BASEDIR)) {
        rubyRuntime.setCurrentDirectory((String) options.get(Options.BASEDIR));
    }

    final Object toFileOption = options.get(Options.TO_FILE);
    if (toFileOption instanceof OutputStream) {
        options.put(Options.TO_FILE, RubyOutputStreamWrapper.wrap(getRubyRuntime(), (OutputStream) toFileOption));
    }

    RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);

    try {
        IRubyObject object = getAsciidoctorModule().callMethod("convert_file",
                rubyRuntime.newString(file.getAbsolutePath()), rubyHash);
        if (NodeConverter.NodeType.DOCUMENT_CLASS.isInstance(object)) {
            // If a document is rendered to a file Asciidoctor returns the document, we return null
            return null;
        }
        return RubyUtils.rubyToJava(rubyRuntime, object, expectedResult);
    } catch (RaiseException e) {
        logger.severe(e.getMessage());

        throw new AsciidoctorCoreException(e);
    } finally {
        // we restore current directory to its original value.
        rubyRuntime.setCurrentDirectory(currentDirectory);
    }
}
 
Example #17
Source File: WhenJavaExtensionGroupIsRegistered.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void extensions_should_be_correctly_added_using_extension_registry() throws IOException {

    // To avoid registering the same extension over and over for all tests,
    // service is instantiated manually.
    this.asciidoctor.createGroup()
        .postprocessor(ArrowsAndBoxesIncludesPostProcessor.class)
        .block("arrowsAndBoxes", ArrowsAndBoxesBlock.class)
        .register();

    Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html"))
            .safe(SafeMode.UNSAFE).get();

    asciidoctor.convertFile(classpath.getResource("arrows-and-boxes-example.ad"), options);

    File renderedFile = new File(testFolder.getRoot(), "rendersample.html");
    org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8");

    Element arrowsJs = doc.select("script[src=http://www.headjump.de/javascripts/arrowsandboxes.js").first();
    assertThat(arrowsJs, is(notNullValue()));

    Element arrowsCss = doc.select("link[href=http://www.headjump.de/stylesheets/arrowsandboxes.css").first();
    assertThat(arrowsCss, is(notNullValue()));

    Element arrowsAndBoxes = doc.select("pre[class=arrows-and-boxes").first();
    assertThat(arrowsAndBoxes, is(notNullValue()));

}
 
Example #18
Source File: RubyGemsPreloader.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public void preloadRequiredLibraries(Map<String, Object> options) {

        if (options.containsKey(Options.ATTRIBUTES)) {
            Map<String, Object> attributes = (Map<String, Object>) options.get(Options.ATTRIBUTES);

            if (isOptionSet(attributes, Attributes.SOURCE_HIGHLIGHTER)
                    && isOptionWithValue(attributes, Attributes.SOURCE_HIGHLIGHTER, CODERAY)) {
                preloadLibrary(Attributes.SOURCE_HIGHLIGHTER);
            }

            if (isOptionSet(attributes, Attributes.CACHE_URI)) {
                preloadLibrary(Attributes.CACHE_URI);
            }

            if (isOptionSet(attributes, Attributes.DATA_URI)) {
                preloadLibrary(Attributes.DATA_URI);
            }
        }

        if (isOptionSet(options, Options.ERUBY) && isOptionWithValue(options, Options.ERUBY, ERUBIS)) {
            preloadLibrary(Options.ERUBY);
        }

        if (isOptionSet(options, Options.TEMPLATE_DIRS)) {
            preloadLibrary(Options.TEMPLATE_DIRS);
        }
        
        if(isOptionSet(options, Options.BACKEND) && "epub3".equalsIgnoreCase((String) options.get(Options.BACKEND))) {
            preloadLibrary(EPUB3);
        }

        if(isOptionSet(options, Options.BACKEND) && "pdf".equalsIgnoreCase((String) options.get(Options.BACKEND))) {
            preloadLibrary(PDF);
        }

        if(isOptionSet(options, Options.BACKEND) && "revealjs".equalsIgnoreCase((String) options.get(Options.BACKEND))) {
            preloadLibrary(REVEALJS);
        }
    }
 
Example #19
Source File: AsciidoctorInvoker.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private String renderInput(Asciidoctor asciidoctor, Options options, List<File> inputFiles) {

        if(inputFiles.size() == 1 && "-".equals(inputFiles.get(0).getName())) {
            return asciidoctor.convert(readInputFromStdIn(), options);
        }

        StringBuilder output = new StringBuilder();

        for (File inputFile : inputFiles) {

            if (inputFile.canRead()) {

                String renderedFile = asciidoctor
                        .convertFile(inputFile, options);
                if (renderedFile != null) {
                    output.append(renderedFile).append(
                            System.getProperty("line.separator"));
                }
            } else {
                System.err.println("asciidoctor: FAILED: input file(s) '"
                        + inputFile.getAbsolutePath()
                        + "' missing or cannot be read");
                throw new IllegalArgumentException(
                        "asciidoctor: FAILED: input file(s) '"
                                + inputFile.getAbsolutePath()
                                + "' missing or cannot be read");
            }
        }

        return output.toString();
    }
 
Example #20
Source File: AsciidoctorEngine.java    From jbake with MIT License 5 votes vote down vote up
private Options getAsciiDocOptionsAndAttributes(ParserContext context) {
    JBakeConfiguration config = context.getConfig();
    List<String> asciidoctorAttributes = config.getAsciidoctorAttributes();
    final AttributesBuilder attributes = attributes(asciidoctorAttributes.toArray(new String[0]));
    if (config.getExportAsciidoctorAttributes()) {
        final String prefix = config.getAttributesExportPrefixForAsciidoctor();

        for (final Iterator<String> it = config.getKeys(); it.hasNext(); ) {
            final String key = it.next();
            if (!key.startsWith("asciidoctor")) {
                attributes.attribute(prefix + key.replace(".", "_"), config.get(key));
            }
        }
    }

    final List<String> optionsSubset = config.getAsciidoctorOptionKeys();
    final Options options = options().attributes(attributes.get()).get();
    for (final String optionKey : optionsSubset) {

        Object optionValue = config.getAsciidoctorOption(optionKey);
        if (optionKey.equals(Options.TEMPLATE_DIRS)) {
            List<String> dirs = getAsList(optionValue);
            if (!dirs.isEmpty()) {
                options.setTemplateDirs(String.valueOf(dirs));
            }
        } else {
            options.setOption(optionKey, optionValue);
        }

    }
    options.setBaseDir(context.getFile().getParentFile().getAbsolutePath());
    options.setSafe(UNSAFE);
    return options;
}
 
Example #21
Source File: DefaultCssResolver.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public boolean isCopyCssActionRequired(Map<String, Object> options) {

        Map<String, Object> attributes = (Map<String, Object>) options.get(Options.ATTRIBUTES);

        if (attributes != null && isCopyCssPresent(attributes)) {
            // if linkcss is not present by default is considered as true.
            if (isLinkCssWithValidValue(attributes)) {
                if (isStylesheetWithValidValue(attributes)) {
                    return true;
                }
            }
        }

        return false;
    }
 
Example #22
Source File: JRubyProcessor.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public org.asciidoctor.ast.List createList(StructuralNode parent, String context,
                                           Map<String, Object> attributes,
                                           Map<Object, Object> options) {

    options.put(Options.ATTRIBUTES, new HashMap<>(attributes));
    return createList(parent, context, options);
}
 
Example #23
Source File: JRubyProcessor.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public Block createBlock(StructuralNode parent, String context, List<String> content, Map<String, Object> attributes,
                         Map<Object, Object> options) {

    options.put(Options.SOURCE, content);
    options.put(Options.ATTRIBUTES, new HashMap<>(attributes));
    return createBlock(parent, context, options);
}
 
Example #24
Source File: JRubyProcessor.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public Block createBlock(StructuralNode parent, String context, String content, Map<String, Object> attributes,
                         Map<Object, Object> options) {

    options.put(Options.SOURCE, content);
    options.put(Options.ATTRIBUTES, attributes);

    return createBlock(parent, context, options);
}
 
Example #25
Source File: BaseProcessor.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public Block createBlock(StructuralNode parent, String context, List<String> content, Map<String, Object> attributes,
                         Map<Object, Object> options) {

    options.put(Options.SOURCE, content);
    options.put(Options.ATTRIBUTES, new HashMap<>(attributes));

    return createBlock(parent, context, options);
}
 
Example #26
Source File: AsciidocConfluencePage.java    From confluence-publisher with Apache License 2.0 5 votes vote down vote up
private static String convertedContent(String adocContent, Options options, Path pagePath, Map<String, String> attachmentCollector, PageTitlePostProcessor pageTitlePostProcessor, Charset sourceEncoding) {
    String content = ASCIIDOCTOR.convert(adocContent, options);
    String postProcessedContent = postProcessContent(content,
            replaceCrossReferenceTargets(pagePath, pageTitlePostProcessor, sourceEncoding),
            collectAndReplaceAttachmentFileNames(attachmentCollector),
            unescapeCdataHtmlContent()
    );

    return postProcessedContent;
}
 
Example #27
Source File: AsciidoctorEngine.java    From jbake with MIT License 4 votes vote down vote up
@Override
public void processHeader(final ParserContext context) {
    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) {
        documentModel.put("title", header.getDocumentTitle().getCombined());
    }
    Map<String, Object> attributes = header.getAttributes();
    for (Map.Entry<String, Object> attribute : attributes.entrySet()) {
        String key = attribute.getKey();
        Object value = attribute.getValue();

        if (hasJBakePrefix(key)) {
            String pKey = key.substring(6);
            if(canCastToString(value)) {
                storeHeaderValue(pKey, (String) value, documentModel);
            } else {
                documentModel.put(pKey, value);
            }
        }
        if (hasRevdate(key) && canCastToString(value)) {

            String dateFormat = context.getConfig().getDateFormat();
            DateFormat df = new SimpleDateFormat(dateFormat);
            try {
                Date date = df.parse((String) value);
                context.setDate(date);
            } catch (ParseException e) {
                LOGGER.error("Unable to parse revdate. Expected {}", dateFormat, e);
            }
        }
        if (key.equals("jbake-tags")) {
            if (canCastToString(value)) {
                context.setTags(((String) value).split(","));
            } else {
                LOGGER.error("Wrong value of 'jbake-tags'. Expected a String got '{}'", getValueClassName(value));
            }
        } else {
            documentModel.put(key, attributes.get(key));
        }
    }
}
 
Example #28
Source File: AsciidoctorEngine.java    From jbake with MIT License 4 votes vote down vote up
private void processAsciiDoc(ParserContext context) {
    Options options = getAsciiDocOptionsAndAttributes(context);
    final Asciidoctor asciidoctor = getEngine(options);
    context.setBody(asciidoctor.convert(context.getBody(), options));
}
 
Example #29
Source File: SiteConversionConfiguration.java    From asciidoctor-maven-plugin with Apache License 2.0 4 votes vote down vote up
public Options getOptions() {
    return options;
}
 
Example #30
Source File: WhenJavaExtensionIsRegistered.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
@Test
public void should_unregister_all_current_registered_extensions() throws IOException {

    JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry();

    javaExtensionRegistry.postprocessor(CustomFooterPostProcessor.class);

    Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html"))
            .safe(SafeMode.UNSAFE).get();

    asciidoctor.unregisterAllExtensions();
    asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options);

    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(), not(containsString("Copyright Acme, Inc.")));
}