Search in sources :

Example 81 with BasedSequence

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

the class HtmlBlockParser method closeBlock.

@Override
public void closeBlock(ParserState state) {
    block.setContent(content);
    content = null;
    // split out inner comments
    if (!(block instanceof HtmlCommentBlock) && parseInnerHtmlComments) {
        // need to break it up into non-comments and comments
        int lastIndex = 0;
        BasedSequence chars = block.getContentChars();
        if (chars.eolLength() > 0)
            chars = chars.midSequence(0, -1);
        // RegEx for HTML can go into an infinite loop, we do manual search to avoid this
        // Matcher matcher = state.getParsing().HTML_COMMENT.matcher(chars);
        // while (matcher.find()) {
        // int index = matcher.start();
        // if (lastIndex < index) {
        // HtmlInnerBlock html = new HtmlInnerBlock(chars.subSequence(lastIndex, index));
        // block.appendChild(html);
        // }
        // 
        // lastIndex = matcher.end();
        // HtmlInnerBlockComment htmlComment = new HtmlInnerBlockComment(chars.subSequence(index, lastIndex));
        // block.appendChild(htmlComment);
        // }
        int length = chars.length();
        while (lastIndex < length) {
            // find the opening HTML comment
            int index = chars.indexOf(HTML_COMMENT_OPEN, lastIndex);
            if (index < 0)
                break;
            // now lets find -->
            int end = chars.indexOf(HTML_COMMENT_CLOSE, index + HTML_COMMENT_OPEN.length());
            // if unterminated, ignore
            if (end < 0)
                break;
            if (lastIndex < index) {
                HtmlInnerBlock html = new HtmlInnerBlock(chars.subSequence(lastIndex, index));
                block.appendChild(html);
            }
            lastIndex = end + HTML_COMMENT_CLOSE.length();
            HtmlInnerBlockComment htmlComment = new HtmlInnerBlockComment(chars.subSequence(index, lastIndex));
            block.appendChild(htmlComment);
        }
        if (lastIndex > 0) {
            if (lastIndex < chars.length()) {
                HtmlInnerBlock html = new HtmlInnerBlock(chars.subSequence(lastIndex, chars.length()));
                block.appendChild(html);
            }
        }
    }
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 82 with BasedSequence

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

the class TextCollectingVisitor method visit.

private void visit(HardLineBreak node) {
    final BasedSequence chars = node.getChars();
    out.append(chars.subSequence(chars.length() - 1, chars.length()));
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 83 with BasedSequence

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

the class FencedCodeBlock method getAstExtra.

@Override
public void getAstExtra(StringBuilder out) {
    BasedSequence content = getContentChars();
    int lines = getContentLines().size();
    segmentSpanChars(out, openingMarker, "open");
    segmentSpanChars(out, info, "info");
    segmentSpan(out, content, "content");
    out.append(" lines[").append(lines).append("]");
    segmentSpanChars(out, closingMarker, "close");
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 84 with BasedSequence

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

the class CoreNodeDocxRenderer method render.

private void render(final Node node, final DocxRendererContext docx) {
    BasedSequence chars = node.getChars();
    MainDocumentPart mdp = docx.getDocxDocument();
    if (node instanceof Block) {
        docx.setBlockFormatProvider(new BlockFormatProviderBase<Node>(docx, docx.getDocxRendererOptions().LOOSE_PARAGRAPH_STYLE));
        docx.createP();
        docx.renderChildren(node);
    } else {
        docx.text(chars.unescape());
    }
}
Also used : MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence) AttributesNode(com.vladsch.flexmark.ext.attributes.AttributesNode) EnumeratedReferenceBlock(com.vladsch.flexmark.ext.enumerated.reference.EnumeratedReferenceBlock) AsideBlock(com.vladsch.flexmark.ext.aside.AsideBlock) SimTocBlock(com.vladsch.flexmark.ext.toc.SimTocBlock) FootnoteBlock(com.vladsch.flexmark.ext.footnotes.FootnoteBlock) TocBlock(com.vladsch.flexmark.ext.toc.TocBlock)

Example 85 with BasedSequence

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

the class InlineParserImpl method parseHtmlInline.

/**
 * Attempt to parse inline HTML.
 *
 * @return true if processed characters false otherwise
 */
@Override
public boolean parseHtmlInline() {
    BasedSequence m = match(myParsing.HTML_TAG);
    if (m != null) {
        // separate HTML comment from herd
        HtmlInlineBase node;
        if (m.startsWith("<!--") && m.endsWith("-->")) {
            node = new HtmlInlineComment(m);
        } else {
            node = new HtmlInline(m);
        }
        appendNode(node);
        return true;
    } else {
        return false;
    }
}
Also used : 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