Search in sources :

Example 11 with BasedSequence

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

the class JiraConverterNodeRenderer method render.

private void render(AutoLink node, NodeRendererContext context, HtmlWriter html) {
    BasedSequence text = node.getText();
    if (context.isDoNotRenderLinks()) {
        html.text(text);
    } else {
        ResolvedLink resolvedLink = context.resolveLink(LinkType.LINK, text, null);
        html.raw("[").raw(text).raw("|").raw(resolvedLink.getUrl());
    }
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 12 with BasedSequence

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

the class FormattingAppendableImpl method popPrefix.

@Override
public FormattingAppendable popPrefix() {
    if (myPrefixStack.isEmpty())
        throw new IllegalStateException("popPrefix with an empty stack");
    BasedSequence prefix = myPrefixStack.pop();
    setPrefix(prefix);
    return this;
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 13 with BasedSequence

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

the class Html5Entities method entityToSequence.

public static BasedSequence entityToSequence(BasedSequence input) {
    Matcher matcher = NUMERIC_PATTERN.matcher(input);
    final BasedSequence baseSeq = input.subSequence(0, 0);
    if (matcher.find()) {
        int base = matcher.end() == 2 ? 10 : 16;
        try {
            int codePoint = Integer.parseInt(input.subSequence(matcher.end(), input.length() - 1).toString(), base);
            if (codePoint == 0) {
                return PrefixedSubSequence.of("\uFFFD", baseSeq);
            }
            return PrefixedSubSequence.of(Arrays.toString(Character.toChars(codePoint)), baseSeq);
        } catch (IllegalArgumentException e) {
            return PrefixedSubSequence.of("\uFFFD", baseSeq);
        }
    } else {
        String name = input.subSequence(1, input.length() - 1).toString();
        String s = NAMED_CHARACTER_REFERENCES.get(name);
        if (s != null) {
            return PrefixedSubSequence.of(s, baseSeq);
        } else {
            return input;
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

Example 14 with BasedSequence

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

the class YouTrackConverterNodeRenderer 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 15 with BasedSequence

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

the class OptionsParser method parseOption.

@Override
public Pair<T, List<ParsedOption<T>>> parseOption(BasedSequence optionsText, T options, MessageProvider provider) {
    ArrayList<ParserMessage> messages = null;
    BasedSequence[] optionsList = optionsText.split(myOptionDelimiter, 0, BasedSequence.SPLIT_TRIM_SKIP_EMPTY);
    T result = options;
    if (provider == null)
        provider = MessageProvider.DEFAULT;
    List<ParsedOption<T>> parsedOptions = new ArrayList<ParsedOption<T>>(optionsList.length);
    for (BasedSequence optionText : optionsList) {
        OptionParser<T> matched = null;
        DelimitedBuilder message = null;
        BasedSequence[] optionList = optionText.split(myOptionValueDelimiter, 2, BasedSequence.SPLIT_SKIP_EMPTY);
        if (optionList.length == 0)
            continue;
        BasedSequence optionName = optionList[0];
        BasedSequence optionValue = optionList.length > 1 ? optionList[1] : optionName.subSequence(optionName.length(), optionName.length());
        for (OptionParser<T> optionParser : myParsableOptions) {
            if (optionParser.getOptionName().equals(optionName.toString())) {
                matched = optionParser;
                message = null;
                break;
            }
            if (optionParser.getOptionName().startsWith(optionName.toString())) {
                if (matched == null) {
                    matched = optionParser;
                } else {
                    if (message == null) {
                        message = new DelimitedBuilder(", ");
                        message.append(provider.message(KEY_OPTION_0_IS_AMBIGUOUS, OPTION_0_IS_AMBIGUOUS, optionName));
                        message.append(matched.getOptionName()).mark();
                    }
                    message.append(optionParser.getOptionName()).mark();
                }
            }
        }
        // have our match
        if (matched != null) {
            if (message == null) {
                Pair<T, List<ParsedOption<T>>> pair = matched.parseOption(optionValue, result, provider);
                result = pair.getFirst();
                parsedOptions.add(new ParsedOption<T>(optionText, this, ParsedOptionStatus.VALID, null, pair.getSecond()));
            } else {
                parsedOptions.add(new ParsedOption<T>(optionText, this, ParsedOptionStatus.ERROR, new ParserMessage(optionName, ParsedOptionStatus.ERROR, message.toString())));
            }
        } else {
            message = new DelimitedBuilder(", ");
            message.append(provider.message(KEY_OPTION_0_DOES_NOT_MATCH, OPTION_0_DOES_NOT_MATCH, optionName));
            appendOptionNames(message);
            parsedOptions.add(new ParsedOption<T>(optionText, this, ParsedOptionStatus.ERROR, new ParserMessage(optionName, ParsedOptionStatus.ERROR, message.toString())));
        }
    }
    return new Pair<T, List<ParsedOption<T>>>(result, parsedOptions);
}
Also used : BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Pair(com.vladsch.flexmark.util.Pair)

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