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());
}
}
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;
}
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;
}
}
}
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();
}
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);
}
Aggregations