Search in sources :

Example 1 with AbbreviationBlock

use of com.vladsch.flexmark.ext.abbreviation.AbbreviationBlock in project flexmark-java by vsch.

the class AbbreviationParagraphPreProcessor method preProcessBlock.

@Override
public int preProcessBlock(Paragraph block, ParserState state) {
    BasedSequence trySequence = block.getChars();
    Matcher matcher = ABBREVIATION_BLOCK.matcher(trySequence);
    int lastFound = 0;
    while (matcher.find()) {
        // abbreviation definition
        if (matcher.start() != lastFound)
            break;
        lastFound = matcher.end();
        int openingStart = matcher.start(1);
        int openingEnd = matcher.end(1);
        int textEnd = lastFound;
        BasedSequence openingMarker = trySequence.subSequence(openingStart, openingStart + 2);
        BasedSequence text = trySequence.subSequence(openingStart + 2, openingEnd - 2).trim();
        BasedSequence closingMarker = trySequence.subSequence(openingEnd - 2, openingEnd);
        AbbreviationBlock abbreviationBlock = new AbbreviationBlock();
        abbreviationBlock.setOpeningMarker(openingMarker);
        abbreviationBlock.setText(text);
        abbreviationBlock.setClosingMarker(closingMarker);
        abbreviationBlock.setAbbreviation(trySequence.subSequence(openingEnd, textEnd).trim());
        abbreviationBlock.setCharsFromContent();
        block.insertBefore(abbreviationBlock);
        state.blockAdded(abbreviationBlock);
        abbreviationMap.put(abbreviationMap.normalizeKey(abbreviationBlock.getText()), abbreviationBlock);
    }
    return lastFound;
}
Also used : AbbreviationBlock(com.vladsch.flexmark.ext.abbreviation.AbbreviationBlock) Matcher(java.util.regex.Matcher) BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Aggregations

AbbreviationBlock (com.vladsch.flexmark.ext.abbreviation.AbbreviationBlock)1 BasedSequence (com.vladsch.flexmark.util.sequence.BasedSequence)1 Matcher (java.util.regex.Matcher)1