use of org.eclipse.mylyn.wikitext.parser.Attributes in project mylyn.docs by eclipse.
the class PreformattedBlock method processLineContent.
@Override
public int processLineContent(String line, int offset) {
int lineStart = usesTag ? 0 : 1;
if (blockLineCount++ == 0) {
Attributes attributes = new Attributes();
if (usesTag) {
Matcher matcher = PRE_OPEN_PATTERN.matcher(line);
if (offset > 0) {
matcher.region(offset, line.length());
}
if (matcher.matches()) {
String htmlAttributes = matcher.group(2);
processHtmlAttributes(attributes, htmlAttributes);
lineStart = matcher.end(1);
offset = lineStart;
} else {
throw new IllegalStateException();
}
}
builder.beginBlock(BlockType.PREFORMATTED, attributes);
}
if (usesTag) {
if (blockLineCount > 0) {
Matcher closeMatcher = PRE_CLOSE_PATTERN.matcher(line);
if (offset > 0) {
closeMatcher.region(offset, line.length());
}
if (closeMatcher.find()) {
int contentEnd = closeMatcher.start(1);
int newContentStart = closeMatcher.end(1);
if (contentEnd > 0) {
addContent(line.substring(0, contentEnd), offset);
}
setClosed(true);
if (newContentStart < line.length()) {
return newContentStart;
}
return -1;
}
}
} else {
if (markupLanguage.isEmptyLine(line) || (offset == 0 && line.charAt(0) != ' ')) {
setClosed(true);
return 0;
}
}
if (line.length() >= lineStart) {
addContent(line, lineStart);
}
return -1;
}
use of org.eclipse.mylyn.wikitext.parser.Attributes in project mylyn.docs by eclipse.
the class DitaTopicDocumentBuilderTest method testDiv.
public void testDiv() {
builder.beginDocument();
builder.beginBlock(BlockType.DIV, new Attributes());
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
builder.characters("foo");
// PARAGRAPH
builder.endBlock();
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
builder.characters("bar");
// PARAGRAPH
builder.endBlock();
// DIV
builder.endBlock();
builder.endDocument();
String dita = out.toString();
assertTrue(Pattern.compile(".*?<topic>\\s*<title></title>\\s*<body>\\s*<p>foo</p>\\s*<p>bar</p>\\s*</body>.*", Pattern.DOTALL).matcher(dita).matches());
}
use of org.eclipse.mylyn.wikitext.parser.Attributes in project mylyn.docs by eclipse.
the class TextileDocumentBuilder method computeSpan.
@Override
protected Block computeSpan(SpanType type, Attributes attributes) {
String appendStyle = null;
switch(type) {
case UNDERLINED:
// $NON-NLS-1$
appendStyle = "text-decoration:underline;";
break;
case MONOSPACE:
// $NON-NLS-1$
appendStyle = "font-family:monospace;";
break;
}
if (appendStyle != null) {
attributes = new Attributes(attributes.getId(), attributes.getCssClass(), attributes.getCssStyle(), attributes.getLanguage());
attributes.appendCssStyle(appendStyle);
}
Block block;
String spanAttributes = computeAttributes(attributes);
switch(type) {
case BOLD:
// $NON-NLS-1$//$NON-NLS-2$
block = new ContentBlock("**" + spanAttributes, "**", true, false, 0, 0);
break;
case CITATION:
// $NON-NLS-1$//$NON-NLS-2$
block = new ContentBlock("??" + spanAttributes, "??", true, false, 0, 0);
break;
case DELETED:
// $NON-NLS-1$//$NON-NLS-2$
block = new ContentBlock("-" + spanAttributes, "-", true, false, 0, 0);
break;
case MARK:
case EMPHASIS:
// $NON-NLS-1$//$NON-NLS-2$
block = new ContentBlock("_" + spanAttributes, "_", true, false, 0, 0);
break;
case INSERTED:
// $NON-NLS-1$//$NON-NLS-2$
block = new ContentBlock("+" + spanAttributes, "+", true, false, 0, 0);
break;
case CODE:
// $NON-NLS-1$//$NON-NLS-2$
block = new ContentBlock("@" + spanAttributes, "@", true, false, 0, 0);
break;
case ITALIC:
// $NON-NLS-1$//$NON-NLS-2$
block = new ContentBlock("__" + spanAttributes, "__", true, false, 0, 0);
break;
case LINK:
if (attributes instanceof LinkAttributes) {
block = new LinkBlock((LinkAttributes) attributes);
} else {
block = new SpanBlock(spanAttributes, true, false);
}
break;
case MONOSPACE:
block = new SpanBlock(spanAttributes, true, false);
break;
case STRONG:
// $NON-NLS-1$//$NON-NLS-2$
block = new ContentBlock("*" + spanAttributes, "*", true, false, 0, 0);
break;
case SUPERSCRIPT:
// $NON-NLS-1$//$NON-NLS-2$
block = new ContentBlock("^" + spanAttributes, "^", true, false, 0, 0);
break;
case SUBSCRIPT:
// $NON-NLS-1$//$NON-NLS-2$
block = new ContentBlock("~" + spanAttributes, "~", true, false, 0, 0);
break;
// case QUOTE: not supported by Textile
case UNDERLINED:
case SPAN:
default:
if (spanAttributes.length() == 0) {
// $NON-NLS-1$
block = new SpanBlock("", true, false);
} else {
block = new SpanBlock(spanAttributes, true, false);
}
break;
}
return block;
}
use of org.eclipse.mylyn.wikitext.parser.Attributes in project mylyn.docs by eclipse.
the class CodeBlock method processLineContent.
@Override
public int processLineContent(String line, int offset) {
if (blockLineCount == 0) {
Attributes attributes = new Attributes();
Textile.configureAttributes(attributes, matcher, 1, true);
offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET);
extended = matcher.group(EXTENDED_GROUP) != null;
builder.beginBlock(BlockType.CODE, attributes);
}
if (markupLanguage.isEmptyLine(line) && !extended) {
setClosed(true);
return 0;
} else if (extended && Textile.explicitBlockBegins(line, offset)) {
setClosed(true);
return offset;
}
++blockLineCount;
final String lineText = offset > 0 ? line.substring(offset) : line;
if (blockLineCount > 1 || lineText.trim().length() > 0) {
builder.characters(lineText);
// $NON-NLS-1$
builder.characters("\n");
}
return -1;
}
use of org.eclipse.mylyn.wikitext.parser.Attributes in project mylyn.docs by eclipse.
the class DefinitionListBlock method processLineContent.
@Override
protected int processLineContent(String line, int offset) {
++blockLineCount;
if (blockLineCount == 1) {
beginBlock(BlockType.DEFINITION_LIST, new ListAttributes());
handleStartTerm();
return -1;
} else {
matcher = START_PATTERN.matcher(line);
if (matcher.matches()) {
closeItems();
handleStartTerm();
return -1;
} else {
String content = line;
int contentOffset = 0;
boolean closeThisLine = false;
if (levelsOpen < 2) {
Matcher ddMatcher = COLON_START_PATTERN.matcher(line);
if (ddMatcher.matches()) {
content = ddMatcher.group(1);
contentOffset = ddMatcher.start(1);
closeItems();
beginBlock(BlockType.DEFINITION_ITEM, new Attributes());
linesThisItem = 0;
closeThisLine = true;
} else {
setClosed(true);
return 0;
}
} else {
// continuation of list item. blank line is termination
if (markupLanguage.isEmptyLine(line)) {
setClosed(true);
return 0;
}
Matcher endMatcher = END_ITEM_PATTERN.matcher(line);
if (endMatcher.matches()) {
content = endMatcher.group(1);
}
}
if (markupLanguage.isEmptyLine(content)) {
closeItems();
return -1;
}
if (++linesThisItem > 1) {
builder.lineBreak();
}
markupLanguage.emitMarkupLine(getParser(), state, contentOffset, content, offset);
if (closeThisLine) {
endBlock();
}
}
}
return -1;
}
Aggregations