Search in sources :

Example 1 with Reverse

use of com.vladsch.flexmark.util.collection.iteration.Reverse in project flexmark-java by vsch.

the class IndentedCodeBlockParser method closeBlock.

@Override
public void closeBlock(ParserState state) {
    // trim trailing blank lines out of the block
    if (trimTrailingBlankLines) {
        int trailingBlankLines = 0;
        List<BasedSequence> lines = content.getLines();
        for (BasedSequence line : new Reverse<BasedSequence>(lines)) {
            if (!line.isBlank())
                break;
            trailingBlankLines++;
        }
        if (trailingBlankLines > 0)
            block.setContent(lines.subList(0, lines.size() - trailingBlankLines));
        else
            block.setContent(content);
    } else {
        block.setContent(content);
    }
    if (codeContentBlock) {
        CodeBlock codeBlock = new CodeBlock(block.getChars(), block.getContentLines());
        block.appendChild(codeBlock);
    }
    content = null;
}
Also used : Reverse(com.vladsch.flexmark.util.collection.iteration.Reverse) BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Aggregations

Reverse (com.vladsch.flexmark.util.collection.iteration.Reverse)1 BasedSequence (com.vladsch.flexmark.util.sequence.BasedSequence)1