use of org.eclipse.mylyn.wikitext.commonmark.internal.Line in project mylyn.docs by eclipse.
the class FencedCodeBlock method process.
@Override
public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) {
Matcher matcher = openingFencePattern.matcher(lineSequence.getCurrentLine().getText());
checkState(matcher.matches());
String indent = matcher.group(1);
boolean indentedCodeBlock = indent != null && indent.length() == 4;
Pattern closingFencePattern = closingFencePattern(matcher);
Attributes codeAttributes = new Attributes();
addInfoTextCssClass(context, codeAttributes, matcher);
builder.setLocator(lineSequence.getCurrentLine().toLocator());
builder.beginBlock(BlockType.CODE, codeAttributes);
if (indentedCodeBlock) {
outputLine(builder, indent, lineSequence.getCurrentLine());
}
lineSequence.advance();
for (Line line : lineSequence.with(Predicates.not(LinePredicates.matches(closingFencePattern)))) {
outputLine(builder, indent, line);
}
if (indentedCodeBlock && lineSequence.getCurrentLine() != null) {
outputLine(builder, indent, lineSequence.getCurrentLine());
}
lineSequence.advance();
builder.endBlock();
}
use of org.eclipse.mylyn.wikitext.commonmark.internal.Line in project mylyn.docs by eclipse.
the class HtmlBlock method process.
@Override
public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) {
for (Line line = lineSequence.getCurrentLine(); line != null && !line.isEmpty(); lineSequence.advance(), line = lineSequence.getCurrentLine()) {
builder.charactersUnescaped(line.getText());
builder.charactersUnescaped("\n");
}
}
use of org.eclipse.mylyn.wikitext.commonmark.internal.Line in project mylyn.docs by eclipse.
the class HtmlCommentBlock method canStart.
@Override
public boolean canStart(LineSequence lineSequence) {
Line line = lineSequence.getCurrentLine();
if (line != null) {
String text = line.getText();
Matcher matcher = startPattern().matcher(text);
if (matcher.matches()) {
int end = matcher.end(1);
if (end < text.length() - 1) {
Matcher doubleHyphenMatcher = doubleHyphen.matcher(text);
doubleHyphenMatcher.region(end, text.length());
if (doubleHyphenMatcher.find()) {
return false;
}
}
return true;
}
}
return false;
}
use of org.eclipse.mylyn.wikitext.commonmark.internal.Line in project mylyn.docs by eclipse.
the class ListBlock method listItemLineSequence.
private LineSequence listItemLineSequence(LineSequence lineSequence) {
final int indentOffset = calculateLineItemIndent(lineSequence.getCurrentLine());
LineSequence itemLinesSequence = lineSequence.with(new Predicate<Line>() {
int firstLineNumber = -1;
@Override
public boolean apply(Line line) {
if (firstLineNumber == -1) {
firstLineNumber = line.getLineNumber();
}
return firstLineNumber == line.getLineNumber() || line.isEmpty() || isIndented(line, indentOffset);
}
});
return itemLinesSequence.transform(new Function<Line, Line>() {
@Override
public Line apply(Line line) {
if (line.isEmpty()) {
return line;
}
int length = Math.max(line.getText().length() - indentOffset, 0);
int offset = Math.min(indentOffset, line.getText().length());
return line.segment(offset, length);
}
});
}
use of org.eclipse.mylyn.wikitext.commonmark.internal.Line in project mylyn.docs by eclipse.
the class SetextHeaderBlock method process.
@Override
public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) {
Line currentLine = lineSequence.getCurrentLine();
Line nextLine = lineSequence.getNextLine();
Matcher matcher = setextUnderlinePattern.matcher(nextLine.getText());
checkState(matcher.matches());
lineSequence.advance();
builder.setLocator(currentLine.toLocator());
int headingLevel = headingLevel(matcher);
TextSegment textSegment = new TextSegment(Collections.singletonList(currentLine));
HeadingAttributes attributes = new HeadingAttributes();
InlineParser inlineParser = context.getInlineParser();
String headingText = inlineParser.toStringContent(context, textSegment);
attributes.setId(context.generateHeadingId(headingLevel, headingText));
builder.beginHeading(headingLevel, attributes);
inlineParser.emit(context, builder, textSegment);
builder.endHeading();
lineSequence.advance();
}
Aggregations