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