Search in sources :

Example 51 with BasedSequence

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

the class JiraConverterNodeRenderer method render.

private void render(FencedCodeBlock node, NodeRendererContext context, HtmlWriter html) {
    BasedSequence info = node.getInfo();
    if (info.isNotNull() && !info.isBlank()) {
        html.line().raw("{code:lang=" + info.unescape() + "}").line();
    } else {
        html.line().raw("{code}").line();
    }
    html.raw(node.getContentChars().normalizeEOL());
    html.line().raw("{code}").blankLine();
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 52 with BasedSequence

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

the class FlexmarkHtmlParser method processCode.

private boolean processCode(FormattingAppendable out, Element element) {
    skip();
    BasedSequence text = SubSequence.of(element.ownText());
    int backTickCount = getMaxRepeatedChars(text, '`', 1);
    CharSequence backTicks = RepeatedCharSequence.of("`", backTickCount);
    boolean oldInlineCode = myInlineCode;
    myInlineCode = true;
    processTextNodes(out, element, backTicks);
    myInlineCode = oldInlineCode;
    return true;
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence) RepeatedCharSequence(com.vladsch.flexmark.util.sequence.RepeatedCharSequence)

Example 53 with BasedSequence

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

the class FlexmarkHtmlParser method getMaxRepeatedChars.

private int getMaxRepeatedChars(final CharSequence text, final char c, int minCount) {
    BasedSequence chars = BasedSequenceImpl.of(text);
    int lastPos = 0;
    while (lastPos < chars.length()) {
        int pos = chars.indexOf(c, lastPos);
        if (pos < 0)
            break;
        int count = chars.countChars(c, pos);
        if (minCount <= count)
            minCount = count + 1;
        lastPos = pos + count;
    }
    return minCount;
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 54 with BasedSequence

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

the class AbbreviationNodePostProcessor method process.

@Override
public void process(NodeTracker state, Node node) {
    if (abbreviations == null)
        return;
    BasedSequence original = node.getChars();
    ReplacedTextMapper textMapper = new ReplacedTextMapper(original);
    BasedSequence literal = Escaping.unescape(original, textMapper);
    Matcher m = abbreviations.matcher(literal);
    int lastEscaped = 0;
    boolean wrapInTextBase = !(node.getParent() instanceof TextBase);
    TextBase textBase = wrapInTextBase ? null : (TextBase) node.getParent();
    while (m.find()) {
        // String found = m.group();
        if (abbreviationMap.containsKey(m.group(0))) {
            BasedSequence abbreviation = abbreviationMap.get(m.group(0));
            BasedSequence toDecorateText = literal.subSequence(m.start(0), m.end(0));
            int startOffset = textMapper.originalOffset(m.start(0));
            int endOffset = textMapper.originalOffset(m.end(0));
            if (wrapInTextBase) {
                wrapInTextBase = false;
                textBase = new TextBase(original);
                node.insertBefore(textBase);
                state.nodeAdded(textBase);
            }
            if (startOffset != lastEscaped) {
                BasedSequence escapedChars = original.subSequence(lastEscaped, startOffset);
                Node node1 = new Text(escapedChars);
                textBase.appendChild(node1);
                state.nodeAdded(node1);
            }
            BasedSequence origToDecorateText = original.subSequence(startOffset, endOffset);
            Abbreviation decorationNode = new Abbreviation(origToDecorateText, abbreviation);
            textBase.appendChild(decorationNode);
            // Text undecoratedTextNode = new Text(origToDecorateText);
            // decorationNode.appendChild(undecoratedTextNode);
            // state.nodeAddedWithChildren(decorationNode);
            state.nodeAdded(decorationNode);
            lastEscaped = endOffset;
        }
    }
    if (lastEscaped > 0) {
        if (lastEscaped != original.length()) {
            BasedSequence escapedChars = original.subSequence(lastEscaped, original.length());
            Node node1 = new Text(escapedChars);
            textBase.appendChild(node1);
            state.nodeAdded(node1);
        }
        node.unlink();
        state.nodeRemoved(node);
    }
}
Also used : Abbreviation(com.vladsch.flexmark.ext.abbreviation.Abbreviation) ReplacedTextMapper(com.vladsch.flexmark.util.sequence.ReplacedTextMapper) Matcher(java.util.regex.Matcher) BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 55 with BasedSequence

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

the class AdmonitionBlock method getAstExtra.

@Override
public void getAstExtra(StringBuilder out) {
    BasedSequence content = getContentChars();
    int lines = getContentLines().size();
    segmentSpanChars(out, openingMarker, "open");
    segmentSpanChars(out, info, "info");
    delimitedSegmentSpanChars(out, titleOpeningMarker, title, titleClosingMarker, "title");
}
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