use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class ZzzzzzDocumentPostProcessor method visit.
private void visit(Text node) {
if (!node.isOrDescendantOfType(DoNotDecorate.class)) {
// do some processing
BasedSequence original = node.getChars();
boolean wrapInTextBase = !(node.getParent() instanceof TextBase);
TextBase textBase = null;
while (wrapInTextBase) {
if (wrapInTextBase) {
wrapInTextBase = false;
textBase = new TextBase(original);
node.insertBefore(textBase);
textBase.appendChild(node);
}
}
}
}
use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class CoreNodeRenderer method render.
private void render(FencedCodeBlock node, NodeRendererContext context, HtmlWriter html) {
html.line();
html.srcPosWithTrailingEOL(node.getChars()).withAttr().tag("pre").openPre();
BasedSequence info = node.getInfo();
if (info.isNotNull() && !info.isBlank()) {
int space = info.indexOf(' ');
BasedSequence language;
if (space == -1) {
language = info;
} else {
language = info.subSequence(0, space);
}
html.attr("class", context.getHtmlOptions().languageClassPrefix + language.unescape());
} else {
String noLanguageClass = context.getHtmlOptions().noLanguageClass.trim();
if (!noLanguageClass.isEmpty()) {
html.attr("class", noLanguageClass);
}
}
html.srcPosWithEOL(node.getContentChars()).withAttr(CODE_CONTENT).tag("code");
if (codeContentBlock) {
context.renderChildren(node);
} else {
html.text(node.getContentChars().normalizeEOL());
}
html.tag("/code");
html.tag("/pre").closePre();
html.lineIf(context.getHtmlOptions().htmlBlockCloseTagEol);
}
use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class DocumentParser method parse.
/**
* The main parsing function. Returns a parsed document AST.
*
* @param source source sequence to parse
* @return Document node of the resulting AST
*/
public Document parse(CharSequence source) {
BasedSequence input = source instanceof BasedSequence ? (BasedSequence) source : SubSequence.of(source);
int lineStart = 0;
int lineBreak;
int lineEOL;
int lineEnd;
lineNumber = 0;
documentBlockParser.initializeDocument(options, input);
inlineParser.initializeDocument(myParsing, documentBlockParser.getBlock());
currentPhase = ParserPhase.PARSE_BLOCKS;
while ((lineBreak = Parsing.findLineBreak(input, lineStart)) != -1) {
BasedSequence line = input.subSequence(lineStart, lineBreak);
lineEOL = lineBreak;
if (lineBreak + 1 < input.length() && input.charAt(lineBreak) == '\r' && input.charAt(lineBreak + 1) == '\n') {
lineEnd = lineBreak + 2;
} else {
lineEnd = lineBreak + 1;
}
this.lineWithEOL = input.subSequence(lineStart, lineEnd);
this.lineStart = lineStart;
this.lineEOLIndex = lineEOL;
this.lineEndIndex = lineEnd;
incorporateLine(line);
lineNumber++;
lineStart = lineEnd;
}
if (input.length() > 0 && (lineStart == 0 || lineStart < input.length())) {
this.lineWithEOL = input.subSequence(lineStart, input.length());
this.lineStart = lineStart;
this.lineEOLIndex = input.length();
this.lineEndIndex = this.lineEOLIndex;
incorporateLine(lineWithEOL);
lineNumber++;
}
return finalizeAndProcess();
}
use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class DocumentParser method addLine.
/**
* Add line content to the active block parser. We assume it can accept lines -- that check should be done before
* calling this.
*/
private void addLine() {
BasedSequence content = lineWithEOL.subSequence(index);
if (columnIsInTab) {
// Our column is in a partially consumed tab. Expand the remaining columns (to the next tab stop) to spaces.
BasedSequence rest = content.subSequence(1);
int spaces = Parsing.columnsToNextTabStop(column);
StringBuilder sb = new StringBuilder(spaces + rest.length());
for (int i = 0; i < spaces; i++) {
sb.append(' ');
}
// sb.append(rest);
content = PrefixedSubSequence.of(sb.toString(), rest);
}
// getActiveBlockParser().addLine(content, content.baseSubSequence(lineEOL, lineEnd));
// BasedSequence eol = content.baseSubSequence(lineEOL < lineEnd ? lineEnd - 1 : lineEnd, lineEnd).toMapped(EolCharacterMapper.INSTANCE);
getActiveBlockParser().addLine(this, content);
}
use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class FencedCodeBlockParser method tryContinue.
@Override
public BlockContinue tryContinue(ParserState state) {
int nextNonSpace = state.getNextNonSpaceIndex();
int newIndex = state.getIndex();
BasedSequence line = state.getLine();
Matcher matcher;
boolean matches = (state.getIndent() <= 3 && nextNonSpace < line.length() && (!matchingCloser || line.charAt(nextNonSpace) == fenceChar));
if (matches) {
BasedSequence trySequence = line.subSequence(nextNonSpace, line.length());
matcher = CLOSING_FENCE.matcher(trySequence);
if (matcher.find()) {
int foundFenceLength = matcher.group(0).length();
if (foundFenceLength >= fenceLength) {
// closing fence - we're at end of line, so we can finalize now
block.setClosingMarker(trySequence.subSequence(0, foundFenceLength));
return BlockContinue.finished();
}
}
}
// skip optional spaces of fence indent
int i = fenceIndent;
while (i > 0 && newIndex < line.length() && line.charAt(newIndex) == ' ') {
newIndex++;
i--;
}
return BlockContinue.atIndex(newIndex);
}
Aggregations