Search in sources :

Example 11 with ListAttributes

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

the class ListBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    if (blockLineCount == 0) {
        ListAttributes attributes = new ListAttributes();
        String spaces = matcher.group(1);
        String listSpec = matcher.group(2);
        String numericListSpec = matcher.group(3);
        if (numericListSpec != null && !"1".equals(numericListSpec)) {
            // $NON-NLS-1$
            attributes.setStart(numericListSpec);
        }
        int level = calculateLevel(spaces);
        BlockType type = listSpec == null ? BlockType.NUMERIC_LIST : BlockType.BULLETED_LIST;
        offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET);
        listState.push(new ListState(level, spaces.length(), offset, type));
        builder.beginBlock(type, attributes);
    } else {
        ListAttributes attributes = new ListAttributes();
        Matcher matcher = startPattern.matcher(line);
        if (!matcher.matches()) {
            Matcher nextLineMatcher = nextLinePattern.matcher(line);
            ListState listState = this.listState.peek();
            if (listState.openItem && nextLineMatcher.matches()) {
                String spaces = nextLineMatcher.group(1);
                if (spaces.length() > 0 && spaces.length() >= listState.numSpaces && spaces.length() <= listState.lineRemainderStart) {
                    ++blockLineCount;
                    offset = nextLineMatcher.start(2) - 1;
                    markupLanguage.emitMarkupLine(getParser(), state, line, offset);
                    return -1;
                }
            }
            setClosed(true);
            return 0;
        }
        String spaces = matcher.group(1);
        String listSpec = matcher.group(2);
        String numericListSpec = matcher.group(3);
        if (numericListSpec != null && !"1".equals(numericListSpec)) {
            // $NON-NLS-1$
            attributes.setStart(numericListSpec);
        }
        int level = calculateLevel(spaces);
        BlockType type = listSpec == null ? BlockType.NUMERIC_LIST : BlockType.BULLETED_LIST;
        offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET);
        for (ListState listState = this.listState.peek(); listState.level != level || listState.type != type; listState = this.listState.peek()) {
            if (listState.level > level || (listState.level == level && listState.type != type)) {
                closeOne();
                if (this.listState.isEmpty()) {
                    this.listState.push(new ListState(1, spaces.length(), offset, type));
                    builder.beginBlock(type, attributes);
                }
            } else {
                this.listState.push(new ListState(level, spaces.length(), offset, type));
                builder.beginBlock(type, attributes);
            }
        }
    }
    ++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) ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes)

Example 12 with ListAttributes

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

the class DocBookDocumentBuilderTest method testOrderedListLoweralphaType.

public void testOrderedListLoweralphaType() {
    builder.beginDocument();
    ListAttributes listAttributes = new ListAttributes();
    listAttributes.setCssStyle("list-style-type: lower-alpha;");
    builder.beginBlock(BlockType.NUMERIC_LIST, listAttributes);
    builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
    builder.characters("item");
    // LI
    builder.endBlock();
    // OL
    builder.endBlock();
    builder.endDocument();
    String docbook = out.toString();
    String expectedContent = "<orderedlist numeration=\"loweralpha\"><listitem><para>item</para></listitem></orderedlist>";
    assertEquals(DOCBOOK_BEGIN_CHAPTER + expectedContent + DOCBOOK_END_CHAPTER, docbook);
}
Also used : ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes) TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes)

Example 13 with ListAttributes

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

the class HtmlDocumentBuilderTest method assertListStyle.

private void assertListStyle(String listStyleType) {
    setup();
    ListAttributes attributes = new ListAttributes();
    attributes.setCssStyle(String.format("list-style-type: %s;", listStyleType));
    builder.setEmitAsDocument(false);
    builder.beginDocument();
    builder.beginBlock(BlockType.NUMERIC_LIST, attributes);
    builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
    builder.characters("first");
    builder.endBlock();
    builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
    builder.characters("second");
    builder.endBlock();
    builder.endBlock();
    builder.endDocument();
    assertEquals("<ol style=\"list-style-type: " + listStyleType + ";\"><li>first</li><li>second</li></ol>", out.toString());
}
Also used : ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes)

Aggregations

ListAttributes (org.eclipse.mylyn.wikitext.parser.ListAttributes)13 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)11 LinkAttributes (org.eclipse.mylyn.wikitext.parser.LinkAttributes)5 TableAttributes (org.eclipse.mylyn.wikitext.parser.TableAttributes)5 Matcher (java.util.regex.Matcher)3 BlockType (org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType)2 ArrayList (java.util.ArrayList)1