Search in sources :

Example 1 with CharacterNodeFactory

use of com.vladsch.flexmark.parser.block.CharacterNodeFactory in project flexmark-java by vsch.

the class InlineParserImpl method processCustomCharacters.

private boolean processCustomCharacters() {
    char c = peek();
    CharacterNodeFactory factory = customSpecialCharacterFactoryMap.get(c);
    if (factory == null)
        return false;
    Node node = factory.create();
    node.setChars(input.subSequence(index, index + 1));
    if (currentText != null) {
        BasedSequence prevText = SegmentedSequence.of(currentText, BasedSequence.NULL);
        currentText = null;
        // see if need to trim some off the end
        int pos = prevText.length();
        BasedSequence skipped = null;
        while (pos > 0 && factory.skipPrev(prevText.charAt(pos - 1))) pos--;
        if (pos < prevText.length()) {
            skipped = prevText.subSequence(pos);
            prevText = prevText.subSequence(0, pos);
        }
        block.appendChild(new Text(prevText));
        if (skipped != null && factory.wantSkippedWhitespace()) {
            block.appendChild(new WhiteSpace(skipped));
        }
    }
    appendNode(node);
    if (customSpecialCharacterNodes == null)
        customSpecialCharacterNodes = new ArrayList<Node>();
    customSpecialCharacterNodes.add(node);
    int pos = index + 1;
    do {
        index++;
        c = peek();
    } while (c != '\0' && factory.skipNext(c));
    if (pos < index && factory.wantSkippedWhitespace()) {
        block.appendChild(new WhiteSpace(input.subSequence(pos, index)));
    }
    return true;
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence) CharacterNodeFactory(com.vladsch.flexmark.parser.block.CharacterNodeFactory)

Aggregations

CharacterNodeFactory (com.vladsch.flexmark.parser.block.CharacterNodeFactory)1 BasedSequence (com.vladsch.flexmark.util.sequence.BasedSequence)1