use of org.eclipse.mylyn.wikitext.parser.ListAttributes in project mylyn.docs by eclipse.
the class ListBlock method adjustLevel.
private void adjustLevel(Matcher matcher, BlockType type, String tag) {
// find correct level for next list item
// default is next level
int level = listState.size() + 1;
for (ListState ls : listState) {
if (ls.tag.equals(tag)) {
// tag already used: drop to that level
level = ls.level;
}
}
for (ListState prevState = listState.peek(); level != prevState.level || prevState.type != type; prevState = listState.peek()) {
if (level > prevState.level) {
if (!prevState.openItem) {
builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
prevState.openItem = true;
}
ListAttributes attributes = new ListAttributes();
if (type == BlockType.NUMERIC_LIST) {
updateStyleAttribute(attributes, tag, null);
}
listState.push(new ListState(tag, prevState.level + 1, type));
builder.beginBlock(type, attributes);
} else {
closeOne();
if (listState.isEmpty()) {
ListAttributes attributes = new ListAttributes();
listState.push(new ListState(tag, 1, type));
builder.beginBlock(type, attributes);
}
}
}
}
use of org.eclipse.mylyn.wikitext.parser.ListAttributes in project mylyn.docs by eclipse.
the class ListBlock method processLineContent.
/**
* AsciiDoc line process with given offset.
*/
@Override
protected int processLineContent(String line, int offset) {
boolean closeItem = true;
// first line processed in current block
if (blockLineCount == 0) {
listState = new Stack<>();
ListAttributes attributes = new ListAttributes();
String listSpec = normalizeListSpec(matcher.group(1));
BlockType type = calculateType(listSpec);
if (type == BlockType.NUMERIC_LIST) {
List<String> positionalParameters = new ArrayList<>();
positionalParameters.add(PARAM_NAME_STYLE);
Map<String, String> lastProperties = getAsciiDocState().getLastProperties(positionalParameters);
getAsciiDocState().setLastPropertiesText("");
String startProperty = lastProperties.get(PARAM_NAME_START);
if (startProperty != null) {
attributes.setStart(startProperty);
}
String styleProperty = lastProperties.get(PARAM_NAME_STYLE);
updateStyleAttribute(attributes, listSpec, styleProperty);
}
// first line of the block could be "** " or more
offset = matcher.start(2);
listState.push(new ListState(listSpec, 1, type));
builder.beginBlock(type, attributes);
adjustLevel(matcher, type, listSpec);
} else if (line.isEmpty()) {
if (!listContinuation) {
blankSeparator = true;
}
return -1;
} else if (isListContinuation(line)) {
// list continuation
blankSeparator = false;
listContinuation = true;
closeItem = false;
return -1;
} else {
Matcher matcher = startPattern.matcher(line);
if (!matcher.matches()) {
if (blankSeparator) {
setClosed(true);
blankSeparator = false;
return 0;
}
closeItem = false;
Matcher leadingBlankMatcher = leadingBlankPattern.matcher(line);
if (leadingBlankMatcher.find()) {
offset = leadingBlankMatcher.end();
}
// $NON-NLS-1$
markupLanguage.emitMarkupText(getParser(), state, " ");
} else {
String listSpec = normalizeListSpec(matcher.group(1));
BlockType type = calculateType(listSpec);
offset = matcher.start(2);
adjustLevel(matcher, type, listSpec);
}
blankSeparator = false;
listContinuation = false;
}
++blockLineCount;
ListState listState = this.listState.peek();
if (closeItem) {
if (listState.openItem) {
builder.endBlock();
}
listState.openItem = true;
builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
}
markupLanguage.emitMarkupLine(getParser(), state, line, offset);
// entire line processed
return -1;
}
use of org.eclipse.mylyn.wikitext.parser.ListAttributes in project mylyn.docs by eclipse.
the class DocBookDocumentBuilderTest method testOrderedListUpperromanType.
public void testOrderedListUpperromanType() {
builder.beginDocument();
ListAttributes listAttributes = new ListAttributes();
listAttributes.setCssStyle("list-style-type: upper-roman;");
builder.beginBlock(BlockType.NUMERIC_LIST, listAttributes);
builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
builder.characters("item");
// LI
builder.endBlock();
// OL
builder.endBlock();
builder.endDocument();
String docbook = out.toString();
String expectedContent = "<orderedlist numeration=\"upperroman\"><listitem><para>item</para></listitem></orderedlist>";
assertEquals(DOCBOOK_BEGIN_CHAPTER + expectedContent + DOCBOOK_END_CHAPTER, docbook);
}
use of org.eclipse.mylyn.wikitext.parser.ListAttributes in project mylyn.docs by eclipse.
the class DocBookDocumentBuilderTest method testOrderedListArabicType.
public void testOrderedListArabicType() {
builder.beginDocument();
ListAttributes listAttributes = new ListAttributes();
listAttributes.setCssStyle("list-style-type: decimal;");
builder.beginBlock(BlockType.NUMERIC_LIST, listAttributes);
builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
builder.characters("item");
// LI
builder.endBlock();
// OL
builder.endBlock();
builder.endDocument();
String docbook = out.toString();
String expectedContent = "<orderedlist numeration=\"arabic\"><listitem><para>item</para></listitem></orderedlist>";
assertEquals(DOCBOOK_BEGIN_CHAPTER + expectedContent + DOCBOOK_END_CHAPTER, docbook);
}
use of org.eclipse.mylyn.wikitext.parser.ListAttributes in project mylyn.docs by eclipse.
the class DocBookDocumentBuilderTest method testOrderedListUpperalphaType.
public void testOrderedListUpperalphaType() {
builder.beginDocument();
ListAttributes listAttributes = new ListAttributes();
listAttributes.setCssStyle("list-style-type: upper-alpha;");
builder.beginBlock(BlockType.NUMERIC_LIST, listAttributes);
builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
builder.characters("item");
// LI
builder.endBlock();
// OL
builder.endBlock();
builder.endDocument();
String docbook = out.toString();
String expectedContent = "<orderedlist numeration=\"upperalpha\"><listitem><para>item</para></listitem></orderedlist>";
assertEquals(DOCBOOK_BEGIN_CHAPTER + expectedContent + DOCBOOK_END_CHAPTER, docbook);
}
Aggregations