Java Code Examples for org.asciidoctor.extension.PreprocessorReader#push_include()

The following examples show how to use org.asciidoctor.extension.PreprocessorReader#push_include() . 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: ClasspathIncludeProcessor.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void process(Document document,
                    PreprocessorReader reader,
                    String target,
                    Map<String, Object> attributes) {
    List<String> content = readContent(target);
    for (int i = content.size() - 1; i >= 0; i--) {
        String line = content.get(i);
        // See also https://github.com/asciidoctor/asciidoctorj/issues/437#issuecomment-192669617
        // Seems to be a hack to avoid mangling of paragraphes
        if (line.trim().equals("")) {
            line = " ";
        }
        reader.push_include(line, target, target, 1, attributes);
    }
}
 
Example 2
Source File: LsIncludeProcessor.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Document document,                    // <3>
                    PreprocessorReader reader,
                    String target,
                    Map<String, Object> attributes) {

    StringBuilder sb = new StringBuilder();

    for (File f: new File(".").listFiles()) {
        sb.append(f.getName()).append("\n");
    }

    reader.push_include(                                  // <4>
            sb.toString(),
            target,
            new File(".").getAbsolutePath(),
            1,
            attributes);
}
 
Example 3
Source File: IncludePreprocessor.java    From helidon-build-tools with Apache License 2.0 4 votes vote down vote up
private List<String> markIncludes(
        PreprocessorReader reader,
        OutputType outputType,
        Map<String, Object> attributes) {

    /*
     * Use the raw input. Do not use reader.readLines() yet because that
     * would trigger {@code include::} handling which needs to happen below.
     */
    List<String> origWithBracketedIncludes = convertHybridToBracketed(reader.lines());

    /*
     * Replace the reader's content with the bracketed format.
     */
    readAndClearReader(reader);
    String origWithBracketedIncludesContent = linesToString(origWithBracketedIncludes);
    reader.push_include(origWithBracketedIncludesContent, null, null, 1, attributes);

    /*
     * Have the reader consume the bracketed-include content which will
     * insert the included text between the bracketing comments.
     */
    List<String> bracketedIncludesWithIncludedText = readAndClearReader(reader);

    /*
     * With the actual included text between the bracketing comments convert
     * that to the numbered format which is ultimate what we want.
     */
    List<String> numberedIncludesWithIncludedText
            = convertBracketedToNumbered(bracketedIncludesWithIncludedText);

    /*
     * Prepare the reader to consume the numbered format just computed.
     */
    String numberedIncludesWithIncludedTextContent = linesToString(numberedIncludesWithIncludedText);
    reader.push_include(
            numberedIncludesWithIncludedTextContent,
            null,
            null,
            1,
            attributes);

    switch (outputType) {
        case PREPROCESSED:
            return numberedIncludesWithIncludedText;

        case NATURAL:
            return convertBracketedToNatural(bracketedIncludesWithIncludedText);

        default:
            throw new IllegalArgumentException(
                    String.format("outputType %s is not one of %s",
                        outputType == null ? "null" : outputType.toString().toLowerCase(),
                        Arrays.toString(OutputType.values())));
    }
}
 
Example 4
Source File: UriIncludeProcessor.java    From asciidoctor-maven-plugin with Apache License 2.0 3 votes vote down vote up
@Override
public void process(Document document, PreprocessorReader reader, String target,
                    Map<String, Object> attributes) {

    System.out.println("Processing "+ this.getClass().getSimpleName());

    StringBuilder content = readContent(target);
    reader.push_include(content.toString(), target, target, 1, attributes);

}