Search in sources :

Example 76 with BasedSequence

use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.

the class ZzzzzzDocumentPostProcessor method visit.

private void visit(Text node) {
    if (!node.isOrDescendantOfType(DoNotDecorate.class)) {
        // do some processing
        BasedSequence original = node.getChars();
        boolean wrapInTextBase = !(node.getParent() instanceof TextBase);
        TextBase textBase = null;
        while (wrapInTextBase) {
            if (wrapInTextBase) {
                wrapInTextBase = false;
                textBase = new TextBase(original);
                node.insertBefore(textBase);
                textBase.appendChild(node);
            }
        }
    }
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 77 with BasedSequence

use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.

the class CoreNodeRenderer method render.

private void render(FencedCodeBlock node, NodeRendererContext context, HtmlWriter html) {
    html.line();
    html.srcPosWithTrailingEOL(node.getChars()).withAttr().tag("pre").openPre();
    BasedSequence info = node.getInfo();
    if (info.isNotNull() && !info.isBlank()) {
        int space = info.indexOf(' ');
        BasedSequence language;
        if (space == -1) {
            language = info;
        } else {
            language = info.subSequence(0, space);
        }
        html.attr("class", context.getHtmlOptions().languageClassPrefix + language.unescape());
    } else {
        String noLanguageClass = context.getHtmlOptions().noLanguageClass.trim();
        if (!noLanguageClass.isEmpty()) {
            html.attr("class", noLanguageClass);
        }
    }
    html.srcPosWithEOL(node.getContentChars()).withAttr(CODE_CONTENT).tag("code");
    if (codeContentBlock) {
        context.renderChildren(node);
    } else {
        html.text(node.getContentChars().normalizeEOL());
    }
    html.tag("/code");
    html.tag("/pre").closePre();
    html.lineIf(context.getHtmlOptions().htmlBlockCloseTagEol);
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 78 with BasedSequence

use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.

the class DocumentParser method parse.

/**
 * The main parsing function. Returns a parsed document AST.
 *
 * @param source source sequence to parse
 * @return Document node of the resulting AST
 */
public Document parse(CharSequence source) {
    BasedSequence input = source instanceof BasedSequence ? (BasedSequence) source : SubSequence.of(source);
    int lineStart = 0;
    int lineBreak;
    int lineEOL;
    int lineEnd;
    lineNumber = 0;
    documentBlockParser.initializeDocument(options, input);
    inlineParser.initializeDocument(myParsing, documentBlockParser.getBlock());
    currentPhase = ParserPhase.PARSE_BLOCKS;
    while ((lineBreak = Parsing.findLineBreak(input, lineStart)) != -1) {
        BasedSequence line = input.subSequence(lineStart, lineBreak);
        lineEOL = lineBreak;
        if (lineBreak + 1 < input.length() && input.charAt(lineBreak) == '\r' && input.charAt(lineBreak + 1) == '\n') {
            lineEnd = lineBreak + 2;
        } else {
            lineEnd = lineBreak + 1;
        }
        this.lineWithEOL = input.subSequence(lineStart, lineEnd);
        this.lineStart = lineStart;
        this.lineEOLIndex = lineEOL;
        this.lineEndIndex = lineEnd;
        incorporateLine(line);
        lineNumber++;
        lineStart = lineEnd;
    }
    if (input.length() > 0 && (lineStart == 0 || lineStart < input.length())) {
        this.lineWithEOL = input.subSequence(lineStart, input.length());
        this.lineStart = lineStart;
        this.lineEOLIndex = input.length();
        this.lineEndIndex = this.lineEOLIndex;
        incorporateLine(lineWithEOL);
        lineNumber++;
    }
    return finalizeAndProcess();
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 79 with BasedSequence

use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.

the class DocumentParser method addLine.

/**
 * Add line content to the active block parser. We assume it can accept lines -- that check should be done before
 * calling this.
 */
private void addLine() {
    BasedSequence content = lineWithEOL.subSequence(index);
    if (columnIsInTab) {
        // Our column is in a partially consumed tab. Expand the remaining columns (to the next tab stop) to spaces.
        BasedSequence rest = content.subSequence(1);
        int spaces = Parsing.columnsToNextTabStop(column);
        StringBuilder sb = new StringBuilder(spaces + rest.length());
        for (int i = 0; i < spaces; i++) {
            sb.append(' ');
        }
        // sb.append(rest);
        content = PrefixedSubSequence.of(sb.toString(), rest);
    }
    // getActiveBlockParser().addLine(content, content.baseSubSequence(lineEOL, lineEnd));
    // BasedSequence eol = content.baseSubSequence(lineEOL < lineEnd ? lineEnd - 1 : lineEnd, lineEnd).toMapped(EolCharacterMapper.INSTANCE);
    getActiveBlockParser().addLine(this, content);
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 80 with BasedSequence

use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.

the class FencedCodeBlockParser method tryContinue.

@Override
public BlockContinue tryContinue(ParserState state) {
    int nextNonSpace = state.getNextNonSpaceIndex();
    int newIndex = state.getIndex();
    BasedSequence line = state.getLine();
    Matcher matcher;
    boolean matches = (state.getIndent() <= 3 && nextNonSpace < line.length() && (!matchingCloser || line.charAt(nextNonSpace) == fenceChar));
    if (matches) {
        BasedSequence trySequence = line.subSequence(nextNonSpace, line.length());
        matcher = CLOSING_FENCE.matcher(trySequence);
        if (matcher.find()) {
            int foundFenceLength = matcher.group(0).length();
            if (foundFenceLength >= fenceLength) {
                // closing fence - we're at end of line, so we can finalize now
                block.setClosingMarker(trySequence.subSequence(0, foundFenceLength));
                return BlockContinue.finished();
            }
        }
    }
    // skip optional spaces of fence indent
    int i = fenceIndent;
    while (i > 0 && newIndex < line.length() && line.charAt(newIndex) == ' ') {
        newIndex++;
        i--;
    }
    return BlockContinue.atIndex(newIndex);
}
Also used : Matcher(java.util.regex.Matcher) BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Aggregations

BasedSequence (com.vladsch.flexmark.util.sequence.BasedSequence)91 Matcher (java.util.regex.Matcher)13 Node (com.vladsch.flexmark.ast.Node)6 ArrayList (java.util.ArrayList)5 MacroClose (com.vladsch.flexmark.ext.xwiki.macros.MacroClose)3 ReplacedTextMapper (com.vladsch.flexmark.util.sequence.ReplacedTextMapper)3 Text (com.vladsch.flexmark.ast.Text)2 AttributesNode (com.vladsch.flexmark.ext.attributes.AttributesNode)2 FootnoteBlock (com.vladsch.flexmark.ext.footnotes.FootnoteBlock)2 Macro (com.vladsch.flexmark.ext.xwiki.macros.Macro)2 Pair (com.vladsch.flexmark.util.Pair)2 RepeatedCharSequence (com.vladsch.flexmark.util.sequence.RepeatedCharSequence)2 Block (com.vladsch.flexmark.ast.Block)1 BulletListItem (com.vladsch.flexmark.ast.BulletListItem)1 Link (com.vladsch.flexmark.ast.Link)1 ListItem (com.vladsch.flexmark.ast.ListItem)1 NodeIterator (com.vladsch.flexmark.ast.NodeIterator)1 OrderedListItem (com.vladsch.flexmark.ast.OrderedListItem)1 Parsing (com.vladsch.flexmark.ast.util.Parsing)1 TextCollectingVisitor (com.vladsch.flexmark.ast.util.TextCollectingVisitor)1