Search in sources :

Example 41 with BasedSequence

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

the class SpecExampleNodeRenderer method render.

private void render(SpecExampleHtml node, NodeRendererContext context, HtmlWriter html) {
    BasedSequence text = node.getChars();
    switch(options.renderAs) {
        case DEFINITION_LIST:
            html.tag("dt").text("Html").tag("/dt").line();
            html.tag("dd");
            render(text, "html", context, html);
            html.tag("/dd").line();
            if (options.renderHtml) {
                html.tag("dt").text("Rendered Html").tag("/dt").line();
                html.tag("dd");
                html.raw(options.renderedHtmlPrefix).rawIndentedPre(text.normalizeEOL()).raw(options.renderedHtmlSuffix).line();
                html.tag("/dd").line();
            }
            break;
        case SECTIONS:
            if (!text.isEmpty()) {
                html.tagVoidLine("hr");
                render(text, "html", context, html);
                if (options.renderHtml) {
                    html.tagVoidLine("hr");
                    html.raw(options.renderedHtmlPrefix).rawIndentedPre(text.normalizeEOL()).raw(options.renderedHtmlSuffix).line();
                }
            }
            break;
        case FENCED_CODE:
        default:
            break;
    }
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 42 with BasedSequence

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

the class WikiNode method setLinkChars.

public void setLinkChars(BasedSequence linkChars, boolean allowAnchors, boolean canEscapePipe, boolean canEscapeAnchor) {
    int length = linkChars.length();
    final int start = this instanceof WikiImage ? 3 : 2;
    openingMarker = linkChars.subSequence(0, start);
    closingMarker = linkChars.subSequence(length - 2, length);
    int pos;
    if (linkIsFirst) {
        pos = linkChars.length() - 2;
        do {
            pos = linkChars.lastIndexOf('|', pos - 1);
        } while (pos != -1 && canEscapePipe && (pos > 0 && linkChars.charAt(pos - 1) == '\\' && (linkChars.subSequence(0, pos).countTrailing('\\') & 1) == 1));
    } else {
        pos = -1;
        do {
            pos = linkChars.indexOf('|', pos + 1);
        } while (pos != -1 && canEscapePipe && (pos > 0 && linkChars.charAt(pos - 1) == '\\' && (linkChars.subSequence(0, pos).countTrailing('\\') & 1) == 1));
    }
    BasedSequence link;
    if (pos < 0) {
        link = linkChars.subSequence(start, length - 2);
    } else {
        textSeparatorMarker = linkChars.subSequence(pos, pos + 1);
        if (linkIsFirst) {
            link = linkChars.subSequence(start, pos);
            text = linkChars.subSequence(pos + 1, length - 2);
        } else {
            text = linkChars.subSequence(start, pos);
            link = linkChars.subSequence(pos + 1, length - 2);
        }
    }
    setLink(link, allowAnchors, canEscapeAnchor);
    if (text.isNull() && allowAnchors && !anchorMarker.isNull()) {
        // have anchor ref, remove it from text
        text = pageRef;
    }
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 43 with BasedSequence

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

the class WikiLinkLinkRefProcessor method updateNodeElements.

@Override
public void updateNodeElements(final Document document, final Node node) {
    assert (node instanceof WikiNode);
    final WikiNode wikiNode = (WikiNode) node;
    if (node instanceof WikiLink && WikiLinkExtension.ALLOW_INLINES.getFrom(document)) {
        // need to update link and pageRef with plain text versions
        if (wikiNode.getText().isNull()) {
            BasedSequence link = new TextCollectingVisitor().collectAndGetSequence(node);
            wikiNode.setLink(link, WikiLinkExtension.ALLOW_ANCHORS.getFrom(document), WikiLinkExtension.ALLOW_ANCHOR_ESCAPE.getFrom(document));
        }
    }
}
Also used : TextCollectingVisitor(com.vladsch.flexmark.ast.util.TextCollectingVisitor) WikiNode(com.vladsch.flexmark.ext.wikilink.WikiNode) BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence) WikiLink(com.vladsch.flexmark.ext.wikilink.WikiLink)

Example 44 with BasedSequence

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

the class SmartsInlineParser method parse.

@Override
public boolean parse(final InlineParser inlineParser) {
    BasedSequence match = inlineParser.match(parsing.SMARTS);
    if (match != null) {
        BasedSequence input = inlineParser.getInput();
        inlineParser.flushTextNode();
        String typographicSmarts;
        if (match.matches(parsing.ELIPSIS))
            typographicSmarts = "&hellip;";
        else if (match.matches(parsing.ELIPSIS_SPACED))
            typographicSmarts = "&hellip;";
        else if (match.matches(parsing.EN_DASH))
            typographicSmarts = "&ndash;";
        else if (match.matches(parsing.EM_DASH))
            typographicSmarts = "&mdash;";
        else
            return false;
        TypographicSmarts smarts = new TypographicSmarts(match, typographicSmarts);
        inlineParser.getBlock().appendChild(smarts);
        return true;
    }
    return false;
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence) TypographicSmarts(com.vladsch.flexmark.ext.typographic.TypographicSmarts)

Example 45 with BasedSequence

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

the class TableBlockParser method parseAlignment.

private static List<TableCell.Alignment> parseAlignment(BasedSequence separatorLine) {
    List<BasedSequence> parts = split(separatorLine);
    List<TableCell.Alignment> alignments = new ArrayList<TableCell.Alignment>();
    for (BasedSequence part : parts) {
        BasedSequence trimmed = part.trim();
        boolean left = trimmed.startsWith(":");
        boolean right = trimmed.endsWith(":");
        TableCell.Alignment alignment = getAlignment(left, right);
        alignments.add(alignment);
    }
    return alignments;
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence) ArrayList(java.util.ArrayList)

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