Search in sources :

Example 51 with Attributes

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);
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 52 with Attributes

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>"));
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) URI(java.net.URI)

Example 53 with Attributes

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("&#xd;", "");
    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());
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) File(java.io.File) URL(java.net.URL) Stylesheet(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder.Stylesheet)

Example 54 with Attributes

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;
}
Also used : Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 55 with Attributes

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;
}
Also used : BlockType(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType) Matcher(java.util.regex.Matcher) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Aggregations

Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)428 LinkAttributes (org.eclipse.mylyn.wikitext.parser.LinkAttributes)248 ImageAttributes (org.eclipse.mylyn.wikitext.parser.ImageAttributes)223 Test (org.junit.Test)176 Matcher (java.util.regex.Matcher)33 ListAttributes (org.eclipse.mylyn.wikitext.parser.ListAttributes)29 TableAttributes (org.eclipse.mylyn.wikitext.parser.TableAttributes)17 StringWriter (java.io.StringWriter)14 BlockType (org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType)12 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)10 Pattern (java.util.regex.Pattern)9 DocumentBuilder (org.eclipse.mylyn.wikitext.parser.DocumentBuilder)9 SpanStrategies (org.eclipse.mylyn.wikitext.html.internal.SpanStrategies)8 Block (org.eclipse.mylyn.wikitext.parser.markup.Block)8 SpanStrategy (org.eclipse.mylyn.wikitext.html.internal.SpanStrategy)6 SubstitutionBlockStrategy (org.eclipse.mylyn.wikitext.html.internal.SubstitutionBlockStrategy)6 SubstitutionSpanStrategy (org.eclipse.mylyn.wikitext.html.internal.SubstitutionSpanStrategy)6 SubstitutionWithoutCssSpanStrategy (org.eclipse.mylyn.wikitext.html.internal.SubstitutionWithoutCssSpanStrategy)6 TableCellAttributes (org.eclipse.mylyn.wikitext.parser.TableCellAttributes)6 EventDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder)6