use of org.eclipse.mylyn.wikitext.parser.Attributes 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.Attributes 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.Attributes in project mylyn.docs by eclipse.
the class CssClassPhraseModifier method newProcessor.
@Override
protected PatternBasedElementProcessor newProcessor() {
return new PatternBasedElementProcessor() {
@Override
public void emit() {
Attributes attributes = new Attributes();
SpanType span = SpanType.SPAN;
String cssClass = group(1);
if (cssClass != null && !cssClass.isEmpty()) {
attributes.setCssClass(cssClass);
} else {
span = SpanType.MARK;
}
getBuilder().beginSpan(span, attributes);
getBuilder().characters(group(2));
getBuilder().endSpan();
}
};
}
use of org.eclipse.mylyn.wikitext.parser.Attributes in project mylyn.docs by eclipse.
the class AsciiDocDocumentBuilderTest method testSpan.
@Test
public void testSpan() {
builder.beginDocument();
builder.characters("prefix ");
builder.beginSpan(SpanType.BOLD, new Attributes());
builder.characters("bold");
builder.endSpan();
builder.characters(" suffix");
builder.endDocument();
assertMarkup("prefix *bold* suffix\n\n");
}
use of org.eclipse.mylyn.wikitext.parser.Attributes in project mylyn.docs by eclipse.
the class AsciiDocDocumentBuilderTest method testImplicitParagraph.
@Test
public void testImplicitParagraph() {
builder.beginDocument();
builder.characters("text1");
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
builder.characters("text2");
builder.endBlock();
builder.characters("text3");
builder.endDocument();
assertMarkup("text1\n\ntext2\n\ntext3\n\n");
}
Aggregations