use of org.eclipse.mylyn.wikitext.parser.Attributes in project mylyn.docs by eclipse.
the class HtmlDocumentBuilder2Test method testNoGratuitousWhitespace.
public void testNoGratuitousWhitespace() {
builder.beginDocument();
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
builder.characters("some para text");
builder.lineBreak();
builder.characters("more para text");
builder.endBlock();
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
builder.characters("second para");
builder.endBlock();
builder.endDocument();
String html = out.toString();
assertTrue(html.indexOf('\r') == -1);
assertTrue(html.indexOf('\n') == -1);
assertEquals("<?xml version='1.0' encoding='utf-8' ?><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body><p>some para text<br/>more para text</p><p>second para</p></body></html>", html);
}
use of org.eclipse.mylyn.wikitext.parser.Attributes in project mylyn.docs by eclipse.
the class HtmlDocumentBuilder2Test method testDefaultTargetForExternalLinks2.
public void testDefaultTargetForExternalLinks2() throws Exception {
builder.setBase(new URI("http://www.notexample.com"));
builder.setDefaultAbsoluteLinkTarget("_external");
builder.beginDocument();
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
builder.link("http://www.example.com", "test");
builder.endBlock();
builder.endDocument();
String html = out.toString();
assertTrue(html.contains("<a href=\"http://www.example.com\" target=\"_external\">test</a>"));
}
use of org.eclipse.mylyn.wikitext.parser.Attributes in project mylyn.docs by eclipse.
the class HtmlDocumentBuilder2Test method testCssStylesheetEmbedded.
public void testCssStylesheetEmbedded() throws Exception {
URL cssResource = HtmlDocumentBuilder2Test.class.getResource("resources/test.css");
File cssFile = new File(cssResource.toURI().getPath());
fileToUrl.put(cssFile, cssResource);
builder.addCssStylesheet(new Stylesheet(cssFile));
builder.beginDocument();
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
builder.characters("some para text");
builder.endBlock();
builder.endDocument();
String html = out.toString();
html = html.replace("
", "");
assertTrue(Pattern.compile("<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/><style type=\"text/css\">\\s*body\\s+\\{\\s+background-image: test-content.png;\\s+\\}\\s*</style></head>", Pattern.MULTILINE).matcher(html).find());
}
use of org.eclipse.mylyn.wikitext.parser.Attributes in project mylyn.docs by eclipse.
the class ListBlock method adjustLevel.
/**
* @param lastChar
* the last character of the list specification, or ' ' if unknown
* @return true if the item is a continuation
*/
private boolean adjustLevel(char lastChar, int lineLevel, BlockType type, BlockType itemType) {
boolean continuation = false;
for (ListState previousState = listState.peek(); lineLevel != previousState.level || previousState.type != type || previousState.itemType != itemType; previousState = listState.peek()) {
if (lineLevel > previousState.level) {
if (!previousState.openItem) {
builder.beginBlock(previousState.itemType, new Attributes());
previousState.openItem = true;
}
Attributes blockAttributes = new Attributes();
if (type == BlockType.BULLETED_LIST && '-' == lastChar) {
// $NON-NLS-1$
blockAttributes.setCssStyle("list-style: square");
}
listState.push(new ListState(previousState.level + 1, type, itemType));
builder.beginBlock(type, blockAttributes);
} else if (lineLevel == previousState.level && previousState.type == type && previousState.itemType != itemType) {
if (previousState.openItem) {
builder.endBlock();
previousState.openItem = false;
}
previousState.itemType = itemType;
} else {
if (lineLevel == previousState.level && lastChar == ':') {
// this is possibly a continuation of the previous item.
if (previousState.itemType != BlockType.DEFINITION_ITEM && previousState.itemType != BlockType.DEFINITION_TERM) {
// we found a continuation
continuation = true;
break;
}
}
closeOne();
if (listState.isEmpty()) {
Attributes blockAttributes = new Attributes();
if (type == BlockType.BULLETED_LIST && '-' == lastChar) {
// $NON-NLS-1$
blockAttributes.setCssStyle("list-style: square");
}
listState.push(new ListState(1, type, itemType));
builder.beginBlock(type, blockAttributes);
}
}
}
return continuation;
}
use of org.eclipse.mylyn.wikitext.parser.Attributes in project mylyn.docs by eclipse.
the class ListBlock method processLineContent.
@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) {
// $NON-NLS-1$
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) {
markupLanguage.emitMarkupLine(getParser(), state, line, offset);
} else {
markupLanguage.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());
markupLanguage.emitMarkupLine(parser, state, definitionOffset, definition, 0);
}
return -1;
}
Aggregations