Search in sources :

Example 6 with BlockType

use of org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType in project mylyn.docs by eclipse.

the class ListBlock method handleItem.

private void handleItem(String text, Matcher itemStartMatcher) {
    if (blockLineCount == 0) {
        // start list block
        BlockType blockType = itemStartMatcher.group(1) != null ? BlockType.BULLETED_LIST : BlockType.NUMERIC_LIST;
        builder.beginBlock(blockType, new Attributes());
        // start item
        builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
    } else {
        if (nestedBlock != null) {
            nestedBlock.setClosed(true);
            nestedBlock = null;
        } else {
            // end list item
            builder.endBlock();
        }
        // start item
        builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
    }
    int contentStart = itemStartMatcher.start(3);
    thisIndentation = contentStart;
    getMarkupLanguage().emitMarkupLine(getParser(), getState(), text, contentStart);
}
Also used : BlockType(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 7 with BlockType

use of org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType 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);
        int level = calculateLevel(listSpec);
        BlockType type = calculateType(listSpec);
        if (type == BlockType.BULLETED_LIST && "-".equals(listSpec)) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            attributes.setCssStyle("list-style: square");
        }
        // 0-offset matches may start with the "*** " prefix.
        offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET);
        listState.push(new ListState(1, type));
        builder.beginBlock(type, attributes);
        adjustLevel(listSpec, level, type);
    } else {
        Matcher matcher = LIST_PATTERN.matcher(line);
        if (!matcher.matches()) {
            boolean empty = offset == 0 && markupLanguage.isEmptyLine(line);
            boolean breaking = ParagraphBlock.paragraphBreakingBlockMatches(getMarkupLanguage(), line, offset);
            if (empty || breaking) {
                setClosed(true);
                return 0;
            } else {
                continuation = true;
            }
        } else {
            String listSpec = matcher.group(1);
            int level = calculateLevel(listSpec);
            BlockType type = calculateType(listSpec);
            offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET);
            adjustLevel(listSpec, level, type);
        }
    }
    ++blockLineCount;
    ListState listState = this.listState.peek();
    if (listState.openItem) {
        if (continuation) {
            builder.lineBreak();
        } else {
            builder.endBlock();
            listState.openItem = false;
        }
    }
    if (!listState.openItem) {
        listState.openItem = true;
        builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
    }
    markupLanguage.emitMarkupLine(getParser(), state, line, offset);
    return -1;
}
Also used : BlockType(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType) Matcher(java.util.regex.Matcher) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 8 with BlockType

use of org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType in project mylyn.docs by eclipse.

the class BlockStrategiesTest method lists.

@Test
public void lists() {
    for (BlockType listType : new BlockType[] { BlockType.BULLETED_LIST, BlockType.NUMERIC_LIST }) {
        BlockStrategies strategies = new BlockStrategies(Sets.newHashSet(listType));
        assertSupported(strategies, listType);
        assertSupported(strategies, BlockType.LIST_ITEM);
    }
}
Also used : BlockType(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType) BlockStrategies(org.eclipse.mylyn.wikitext.html.internal.BlockStrategies) Test(org.junit.Test)

Example 9 with BlockType

use of org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType in project mylyn.docs by eclipse.

the class BlockStrategiesTest method createNonEmpty.

@Test
public void createNonEmpty() {
    BlockStrategies strategies = new BlockStrategies(Sets.newHashSet(BlockType.PARAGRAPH, BlockType.CODE));
    assertSupported(strategies, BlockType.PARAGRAPH);
    assertSupported(strategies, BlockType.CODE);
    for (BlockType blockType : BlockType.values()) {
        assertNotNull(strategies.getStrategy(blockType, new Attributes()));
    }
}
Also used : BlockType(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) BlockStrategies(org.eclipse.mylyn.wikitext.html.internal.BlockStrategies) Test(org.junit.Test)

Example 10 with BlockType

use of org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType in project mylyn.docs by eclipse.

the class ListBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    if (blockLineCount == 0) {
        listState = new Stack<ListState>();
        Attributes attributes = new Attributes();
        String listSpec = matcher.group(1);
        int level = calculateLevel(listSpec);
        BlockType type = calculateType(listSpec);
        // 0-offset matches may start with the "*** " prefix.
        Textile.configureAttributes(attributes, matcher, 2, true);
        offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET);
        listState.push(new ListState(1, type));
        builder.beginBlock(type, attributes);
        adjustLevel(matcher, level, type);
    } else {
        Matcher matcher = startPattern.matcher(line);
        if (!matcher.matches()) {
            setClosed(true);
            return 0;
        }
        String listSpec = matcher.group(1);
        int level = calculateLevel(listSpec);
        BlockType type = calculateType(listSpec);
        offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET);
        adjustLevel(matcher, level, type);
    }
    ++blockLineCount;
    ListState listState = this.listState.peek();
    if (listState.openItem) {
        builder.endBlock();
    }
    listState.openItem = true;
    builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
    markupLanguage.emitMarkupLine(getParser(), state, line, offset);
    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

BlockType (org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType)14 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)12 Matcher (java.util.regex.Matcher)8 BlockStrategies (org.eclipse.mylyn.wikitext.html.internal.BlockStrategies)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 ListAttributes (org.eclipse.mylyn.wikitext.parser.ListAttributes)2 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)2 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 BlockStrategy (org.eclipse.mylyn.wikitext.html.internal.BlockStrategy)1 NoOpBlockStrategy (org.eclipse.mylyn.wikitext.html.internal.NoOpBlockStrategy)1 SubstitutionBlockStrategy (org.eclipse.mylyn.wikitext.html.internal.SubstitutionBlockStrategy)1 SupportedBlockStrategy (org.eclipse.mylyn.wikitext.html.internal.SupportedBlockStrategy)1 UnsupportedBlockStrategy (org.eclipse.mylyn.wikitext.html.internal.UnsupportedBlockStrategy)1 DocumentBuilder (org.eclipse.mylyn.wikitext.parser.DocumentBuilder)1