Search in sources :

Example 6 with ListAttributes

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

the class DocBookDocumentBuilderTest method testOrderedListLowerromanType.

public void testOrderedListLowerromanType() {
    builder.beginDocument();
    ListAttributes listAttributes = new ListAttributes();
    listAttributes.setCssStyle("list-style-type: lower-roman;");
    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=\"lowerroman\"><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 7 with ListAttributes

use of org.eclipse.mylyn.wikitext.parser.ListAttributes 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;
}
Also used : 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 8 with ListAttributes

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

the class ListBlock method process.

private void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence, ListItemHandler listItemHandler) {
    builder.setLocator(lineSequence.getCurrentLine().toLocator());
    char bulletType = bulletType(lineSequence.getCurrentLine());
    ListAttributes listAttributes = new ListAttributes();
    listAttributes.setStart(listStart(lineSequence.getCurrentLine()));
    ListMode listMode = calculateListMode(context, lineSequence.lookAhead(), bulletType);
    builder.beginBlock(listBlockType(bulletType), listAttributes);
    while (currentLineIsInList(lineSequence, bulletType)) {
        builder.setLocator(lineSequence.getCurrentLine().toLocator());
        builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
        emitListItem(context, builder, listMode, lineSequence);
        builder.endBlock();
    }
    builder.endBlock();
}
Also used : ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes)

Example 9 with ListAttributes

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

the class DefinitionListBlock method openLevel.

private void openLevel(int level) {
    if (!isCurrentLevel(0) && !blockItemIsOpen) {
        openItemBlock("", 0);
    }
    builder.beginBlock(BlockType.DEFINITION_LIST, new ListAttributes());
    levels.push(level);
    blockItemIsOpen = false;
}
Also used : ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes)

Example 10 with ListAttributes

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

the class XslfoDocumentBuilder method beginBlock.

@Override
public void beginBlock(BlockType type, Attributes attributes) {
    BlockInfo thisInfo = new BlockInfo(type);
    BlockInfo parentBlock = findCurrentBlock();
    String cssStyles = blockTypeToCssStyles.get(type);
    Map<String, String> attrs = cssStyles == null ? null : attributesFromCssStyles(cssStyles);
    if (attributes.getCssStyle() != null) {
        Map<String, String> otherAttrs = attributesFromCssStyles(attributes.getCssStyle());
        if (attrs == null) {
            attrs = otherAttrs;
        } else if (!otherAttrs.isEmpty()) {
            attrs.putAll(otherAttrs);
        }
    }
    switch(type) {
        case DEFINITION_LIST:
        case BULLETED_LIST:
        case NUMERIC_LIST:
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "list-block");
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("provisional-label-separation", "0.2em");
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("provisional-distance-between-starts", "1.2em");
            if (findBlockInfo(BlockType.LIST_ITEM) == null) {
                addSpaceBefore();
            }
            break;
        case DEFINITION_ITEM:
            if (parentBlock == null || parentBlock.type != BlockType.DEFINITION_LIST) {
                throw new IllegalStateException();
            }
            boolean firstItem = false;
            if (parentBlock.previousChild != null && parentBlock.previousChild.type == BlockType.DEFINITION_TERM) {
                firstItem = true;
                // list-item-label
                writer.writeEndElement();
                --parentBlock.size;
                // $NON-NLS-1$
                writer.writeStartElement(foNamespaceUri, "list-item-body");
                ++parentBlock.size;
                // $NON-NLS-1$ //$NON-NLS-2$
                writer.writeAttribute("start-indent", "body-start()");
                // $NON-NLS-1$
                writer.writeEmptyElement(foNamespaceUri, "block");
            }
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "block");
            if (attrs == null || !attrs.containsKey("font-size")) {
                // $NON-NLS-1$
                configureFontSize(0);
            }
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            writer.writeAttribute("space-before", firstItem ? "1.2em" : "0.2em");
            break;
        case DEFINITION_TERM:
            if (parentBlock == null || parentBlock.type != BlockType.DEFINITION_LIST) {
                throw new IllegalStateException();
            }
            if (parentBlock.previousChild != null && parentBlock.previousChild.type == BlockType.DEFINITION_ITEM) {
                // list-item-body
                writer.writeEndElement();
                --parentBlock.size;
                // list-item
                writer.writeEndElement();
                --parentBlock.size;
            }
            if (parentBlock.previousChild == null || parentBlock.previousChild.type != BlockType.DEFINITION_TERM) {
                // $NON-NLS-1$
                writer.writeStartElement(foNamespaceUri, "list-item");
                // $NON-NLS-1$ //$NON-NLS-2$
                writer.writeAttribute("space-before", "0.2em");
                ++parentBlock.size;
                // $NON-NLS-1$
                writer.writeStartElement(foNamespaceUri, "list-item-label");
                // $NON-NLS-1$ //$NON-NLS-2$
                writer.writeAttribute("end-indent", "label-end()");
                ++parentBlock.size;
            }
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "block");
            if (attrs == null || !attrs.containsKey("font-size")) {
                // $NON-NLS-1$
                configureFontSize(0);
            }
            if (attrs == null || !attrs.containsKey("font-weight")) {
                // $NON-NLS-1$
                // $NON-NLS-1$//$NON-NLS-2$
                writer.writeAttribute("font-weight", "bold");
            }
            break;
        case LIST_ITEM:
            BlockInfo listInfo = getListBlockInfo();
            ++listInfo.listItemCount;
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "list-item");
            // addSpaceBefore();
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "list-item-label");
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("end-indent", "label-end()");
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "block");
            configureFontSize(0);
            // FIXME: nested list numbering, list style
            if (listInfo.type == BlockType.NUMERIC_LIST) {
                if (attributes instanceof ListAttributes) {
                    // start attribute
                    ListAttributes listAttributes = (ListAttributes) attributes;
                    if (listAttributes.getStart() != null) {
                        try {
                            thisInfo.listItemCount = Integer.parseInt(listAttributes.getStart(), 10) - 1;
                        } catch (NumberFormatException e) {
                        // ignore
                        }
                    }
                }
                // $NON-NLS-1$
                writer.writeCharacters(String.format("%s.", listInfo.listItemCount));
            } else {
                writer.writeCharacters(BULLET_CHARS, 0, BULLET_CHARS.length);
            }
            // block
            writer.writeEndElement();
            // list-item-label
            writer.writeEndElement();
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "list-item-body");
            ++thisInfo.size;
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("start-indent", "body-start()");
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "block");
            configureFontSize(0);
            ++thisInfo.size;
            break;
        case FOOTNOTE:
        case PARAGRAPH:
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "block");
            if (attrs == null || !attrs.containsKey("font-size")) {
                // $NON-NLS-1$
                configureFontSize(0);
            }
            addSpaceBefore();
            break;
        case CODE:
        case PREFORMATTED:
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "block");
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("hyphenate", "false");
            // writer.writeAttribute("wrap-option", "no-wrap"); //$NON-NLS-1$ //$NON-NLS-2$
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("white-space-collapse", "false");
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("white-space-treatment", "preserve");
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("linefeed-treatment", "preserve");
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("text-align", "start");
            if (attrs == null || !attrs.containsKey("font-size")) {
                // $NON-NLS-1$
                configureFontSize(0);
            }
            addSpaceBefore();
            break;
        case QUOTE:
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "block");
            if (attrs == null || !attrs.containsKey("font-size")) {
                // $NON-NLS-1$
                configureFontSize(0);
            }
            // indent
            // $NON-NLS-1$
            indentLeftAndRight(attrs, "2em");
            addSpaceBefore();
            break;
        case DIV:
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "block");
            if (attrs == null || !attrs.containsKey("font-size")) {
                // $NON-NLS-1$
                configureFontSize(0);
            }
            // no space before
            break;
        case INFORMATION:
        case NOTE:
        case TIP:
        case WARNING:
        case PANEL:
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "block");
            if (attrs == null || !attrs.containsKey("font-size")) {
                // $NON-NLS-1$
                configureFontSize(0);
            }
            // $NON-NLS-1$
            indentLeftAndRight(attrs, "2em");
            addSpaceBefore();
            // create the titled panel effect if a title is specified
            if (attributes.getTitle() != null || configuration.panelText) {
                // $NON-NLS-1$
                writer.writeStartElement(foNamespaceUri, "block");
                if (configuration.panelText) {
                    String text = null;
                    switch(type) {
                        case NOTE:
                            // $NON-NLS-1$
                            text = Messages.getString("XslfoDocumentBuilder.Note");
                            break;
                        case TIP:
                            // $NON-NLS-1$
                            text = Messages.getString("XslfoDocumentBuilder.Tip");
                            break;
                        case WARNING:
                            // $NON-NLS-1$
                            text = Messages.getString("XslfoDocumentBuilder.Warning");
                            break;
                    }
                    if (text != null) {
                        // $NON-NLS-1$
                        writer.writeStartElement(foNamespaceUri, "inline");
                        // $NON-NLS-1$//$NON-NLS-2$
                        writer.writeAttribute("font-style", "italic");
                        characters(text);
                        // inline
                        writer.writeEndElement();
                    }
                }
                if (attributes.getTitle() != null) {
                    // $NON-NLS-1$
                    writer.writeStartElement(foNamespaceUri, "inline");
                    // $NON-NLS-1$//$NON-NLS-2$
                    writer.writeAttribute("font-weight", "bold");
                    characters(attributes.getTitle());
                    // inline
                    writer.writeEndElement();
                }
                // block
                writer.writeEndElement();
            }
            break;
        case TABLE:
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "table");
            applyTableAttributes(attributes);
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "table-body");
            ++thisInfo.size;
            break;
        case TABLE_CELL_HEADER:
        case TABLE_CELL_NORMAL:
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "table-cell");
            applyTableCellAttributes(attributes);
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("padding-left", "2pt");
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("padding-right", "2pt");
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("padding-top", "2pt");
            // $NON-NLS-1$ //$NON-NLS-2$
            writer.writeAttribute("padding-bottom", "2pt");
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "block");
            if (attrs == null || !attrs.containsKey("font-size")) {
                // $NON-NLS-1$
                configureFontSize(0);
            }
            ++thisInfo.size;
            break;
        case TABLE_ROW:
            // $NON-NLS-1$
            writer.writeStartElement(foNamespaceUri, "table-row");
            applyTableRowAttributes(attributes);
            break;
        default:
            throw new IllegalStateException(type.name());
    }
    if (attrs != null) {
        // output attributes with stable order
        for (Entry<String, String> ent : new TreeMap<String, String>(attrs).entrySet()) {
            writer.writeAttribute(ent.getKey(), ent.getValue());
        }
    }
    if (parentBlock != null) {
        parentBlock.previousChild = thisInfo;
    }
    elementInfos.push(thisInfo);
}
Also used : 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