@Override
public int processLineContent(String line,int offset) {
boolean continuation = false;
if (blockLineCount == 0) {
listState = new Stack<ListState>();
Attributes attributes = new Attributes();
String listSpec = matcher.group(1);
char lastChar = listSpec.charAt(listSpec.length()-1);
int level = calculateLevel(listSpec);
BlockType type = calculateType(lastChar);
BlockType itemType = calculateItemType(lastChar);
if (type == BlockType.BULLETED_LIST && '-' == lastChar) {
attributes.setCssStyle("list-style: square");
}
offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET);
listState.push(new ListState(1,type,itemType));
builder.beginBlock(type, attributes);
adjustLevel(lastChar, level, type, itemType);
} else {
Matcher matcher = startPattern.matcher(line);
if (!matcher.matches()) {
setClosed(true);
return 0;
}
String listSpec = matcher.group(1);
char lastChar = listSpec.charAt(listSpec.length()-1);
int lineLevel = calculateLevel(listSpec);
BlockType type = calculateType(lastChar);
BlockType itemType = calculateItemType(lastChar);
offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET);
continuation = adjustLevel(lastChar, lineLevel, type, itemType);
}
++blockLineCount;
ListState listState = this.listState.peek();
if (!continuation && listState.openItem) {
listState.openItem = false;
builder.endBlock();
}
if (!listState.openItem) {
listState.openItem = true;
builder.beginBlock(listState.itemType, new Attributes());
}
String definition = null;
int definitionOffset = -1;
if (listState.itemType == BlockType.DEFINITION_TERM) {
// detect definition on same line as term
Matcher definitionMatcher = definitionPattern.matcher(line);
if (offset > 0) {
definitionMatcher.region(offset, line.length());
}
if (definitionMatcher.find()) {
line = line.substring(offset,definitionMatcher.start(1));
offset = 0;
definition = definitionMatcher.group(2);
definitionOffset = definitionMatcher.start(2);
}
}
if (definition == null) {
dialect.emitMarkupLine(getParser(),state,line, offset);
} else {
dialect.emitMarkupLine(getParser(),state,offset,line,0);
}
if (definition != null) {
listState.openItem = false;
builder.endBlock();
adjustLevel(' ',listState.level,BlockType.DEFINITION_LIST,BlockType.DEFINITION_ITEM);
listState = this.listState.peek();
if (listState.openItem) {
builder.endBlock();
}
listState.openItem = true;
builder.beginBlock(listState.itemType, new Attributes());
dialect.emitMarkupLine(parser, state,definitionOffset, definition,0);
}
return -1;