Search in sources :

Example 1 with TableAttributes

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

the class DocBookDocumentBuilderTest method testTableClass.

public void testTableClass() {
    builder.beginDocument();
    TableAttributes tableAttributes = new TableAttributes();
    tableAttributes.appendCssClass("foo");
    builder.beginBlock(BlockType.TABLE, tableAttributes);
    builder.beginBlock(BlockType.TABLE_ROW, new Attributes());
    builder.beginBlock(BlockType.TABLE_CELL_NORMAL, new Attributes());
    builder.characters("text");
    // cell
    builder.endBlock();
    // row
    builder.endBlock();
    // table
    builder.endBlock();
    builder.endDocument();
    String docbook = out.toString();
    String expectedContent = "<informaltable role=\"foo\"><tr><td>text</td></tr></informaltable>";
    assertEquals(DOCBOOK_BEGIN_CHAPTER + expectedContent + DOCBOOK_END_CHAPTER, docbook);
}
Also used : 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) TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes)

Example 2 with TableAttributes

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

the class TableBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    if (blockLineCount++ == 0) {
        TableAttributes attributes = new TableAttributes();
        // first line opens table
        String options = matcher.group(1);
        if (options != null) {
            Matcher optionsMatcher = optionsPattern.matcher(options);
            while (optionsMatcher.find()) {
                String optionName = optionsMatcher.group(1);
                String optionValue = optionsMatcher.group(2);
                if (optionName.equalsIgnoreCase("id")) {
                    // $NON-NLS-1$
                    attributes.setId(optionValue);
                } else if (optionName.equalsIgnoreCase("style")) {
                    // $NON-NLS-1$
                    attributes.setCssStyle(optionValue);
                } else if (optionName.equalsIgnoreCase("class")) {
                    // $NON-NLS-1$
                    attributes.setCssClass(optionValue);
                } else if (optionName.equalsIgnoreCase("title")) {
                    // $NON-NLS-1$
                    attributes.setTitle(optionValue);
                } else if (optionName.equalsIgnoreCase("border")) {
                    // $NON-NLS-1$
                    attributes.setBorder(optionValue);
                } else if (optionName.equalsIgnoreCase("summary")) {
                    // $NON-NLS-1$
                    attributes.setSummary(optionValue);
                } else if (optionName.equalsIgnoreCase("width")) {
                    // $NON-NLS-1$
                    attributes.setWidth(optionValue);
                } else if (optionName.equalsIgnoreCase("frame")) {
                    // $NON-NLS-1$
                    attributes.setFrame(optionValue);
                } else if (optionName.equalsIgnoreCase("rules")) {
                    // $NON-NLS-1$
                    attributes.setRules(optionValue);
                } else if (optionName.equalsIgnoreCase("cellspacing")) {
                    // $NON-NLS-1$
                    attributes.setCellspacing(optionValue);
                } else if (optionName.equalsIgnoreCase("cellpadding")) {
                    // $NON-NLS-1$
                    attributes.setCellpadding(optionValue);
                } else if (optionName.equalsIgnoreCase("bgcolor")) {
                    // $NON-NLS-1$
                    attributes.setBgcolor(optionValue);
                }
            }
        }
        builder.beginBlock(BlockType.TABLE, attributes);
        // table open line never has cells
        return -1;
    } else {
        Matcher newRowMatcher = newRowPattern.matcher(line);
        if (newRowMatcher.matches()) {
            TableRowAttributes attributes = new TableRowAttributes();
            String newRowOptions = newRowMatcher.group(1);
            if (newRowOptions != null) {
                Matcher optionsMatcher = optionsPattern.matcher(newRowOptions);
                while (optionsMatcher.find()) {
                    String optionName = optionsMatcher.group(1);
                    String optionValue = optionsMatcher.group(2);
                    if (optionName.equalsIgnoreCase("id")) {
                        // $NON-NLS-1$
                        attributes.setId(optionValue);
                    } else if (optionName.equalsIgnoreCase("style")) {
                        // $NON-NLS-1$
                        attributes.setCssStyle(optionValue);
                    } else if (optionName.equalsIgnoreCase("class")) {
                        // $NON-NLS-1$
                        attributes.setCssClass(optionValue);
                    } else if (optionName.equalsIgnoreCase("title")) {
                        // $NON-NLS-1$
                        attributes.setTitle(optionValue);
                    } else if (optionName.equalsIgnoreCase("align")) {
                        // $NON-NLS-1$
                        attributes.setAlign(optionValue);
                    } else if (optionName.equalsIgnoreCase("valign")) {
                        // $NON-NLS-1$
                        attributes.setValign(optionValue);
                    } else if (optionName.equalsIgnoreCase("bgcolor")) {
                        // $NON-NLS-1$
                        attributes.setBgcolor(optionValue);
                    }
                }
            }
            openRow(newRowMatcher.start(), attributes);
            return -1;
        } else {
            Matcher endMatcher = endPattern.matcher(line);
            if (endMatcher.matches()) {
                setClosed(true);
                return endMatcher.start(1);
            } else {
                Matcher cellMatcher = cellPattern.matcher(line);
                if (cellMatcher.matches()) {
                    String kind = cellMatcher.group(1);
                    // $NON-NLS-1$
                    BlockType type = ("!".equals(kind)) ? BlockType.TABLE_CELL_HEADER : BlockType.TABLE_CELL_NORMAL;
                    String contents = cellMatcher.group(2);
                    if (contents == null) {
                        // cell was just opened, no cell options.
                        openCell(cellMatcher.start(), type, new TableCellAttributes());
                        return -1;
                    }
                    int contentsStart = cellMatcher.start(2);
                    emitCells(contentsStart, type, contents);
                    return -1;
                } else {
                    // in case of cells this will be handled with NestedBlocks
                    return -1;
                }
            }
        }
    }
}
Also used : TableRowAttributes(org.eclipse.mylyn.wikitext.parser.TableRowAttributes) Matcher(java.util.regex.Matcher) BlockType(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType) TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes) TableCellAttributes(org.eclipse.mylyn.wikitext.parser.TableCellAttributes)

Example 3 with TableAttributes

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

the class XslfoDocumentBuilder method applyTableAttributes.

private void applyTableAttributes(Attributes attributes) {
    // applyAttributes(attributes);
    boolean haveWidth = false;
    if (attributes instanceof TableAttributes) {
        TableAttributes tableAttributes = (TableAttributes) attributes;
        if (tableAttributes.getBgcolor() != null) {
            writer.writeAttribute(CSS_RULE_BACKGROUND_COLOR, tableAttributes.getBgcolor());
        }
        // }
        if (tableAttributes.getWidth() != null) {
            // $NON-NLS-1$
            writer.writeAttribute("width", tableAttributes.getWidth());
            haveWidth = true;
        }
    }
    // FIXME default border
    if (!haveWidth) {
        // $NON-NLS-1$ //$NON-NLS-2$
        writer.writeAttribute("width", "auto");
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    writer.writeAttribute("border-collapse", "collapse");
}
Also used : TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes)

Example 4 with TableAttributes

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

the class SplittingHtmlDocumentBuilder method emitNavigation.

private void emitNavigation(boolean header) {
    String currentName = currentFile.getName();
    List<SplitOutlineItem> pageOrder = outline.getPageOrder();
    SplitOutlineItem previous = null;
    SplitOutlineItem next = null;
    SplitOutlineItem current = null;
    boolean foundPage = false;
    for (SplitOutlineItem page : pageOrder) {
        if (page.getSplitTarget().equals(currentName)) {
            foundPage = true;
            current = page;
        } else if (!foundPage) {
            previous = page;
        } else {
            next = page;
            break;
        }
    }
    boolean rootPage = rootFile.getName().equals(currentFile.getName());
    if (next == null && previous == null && rootPage) {
        return;
    }
    if (!header) {
        // $NON-NLS-1$
        out.charactersUnescaped("<hr class=\"navigation-separator\"/>");
    }
    TableAttributes tableAttributes = new TableAttributes();
    // $NON-NLS-1$
    tableAttributes.setCssClass("navigation");
    // $NON-NLS-1$
    tableAttributes.setCssStyle("width: 100%;");
    // $NON-NLS-1$
    tableAttributes.setBorder("0");
    // $NON-NLS-1$
    tableAttributes.setSummary("navigation");
    out.beginBlock(BlockType.TABLE, tableAttributes);
    TableCellAttributes tableCellAttributes;
    if (header) {
        // header row, emit title of page
        out.beginBlock(BlockType.TABLE_ROW, new Attributes());
        tableCellAttributes = new TableCellAttributes();
        // $NON-NLS-1$
        tableCellAttributes.setAlign("center");
        // $NON-NLS-1$
        tableCellAttributes.setCssStyle("width: 100%");
        // $NON-NLS-1$
        tableCellAttributes.setColspan("3");
        out.beginBlock(BlockType.TABLE_CELL_HEADER, tableCellAttributes);
        if (rootPage) {
            out.characters(rootBuilder.getTitle());
        } else {
            // $NON-NLS-1$
            out.characters(current == null ? "" : current.getLabel());
        }
        out.endBlock();
        out.endBlock();
    }
    // navigation row
    out.beginBlock(BlockType.TABLE_ROW, new Attributes());
    LinkAttributes linkAttributes;
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("left");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 20%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (previous != null) {
        linkAttributes = new LinkAttributes();
        linkAttributes.setTitle(previous.getLabel());
        if (navigationImages) {
            ImageAttributes imageAttributes = new ImageAttributes();
            // $NON-NLS-1$
            imageAttributes.setAlt(Messages.getString("SplittingHtmlDocumentBuilder.Previous"));
            out.imageLink(linkAttributes, imageAttributes, previous.getSplitTarget(), // $NON-NLS-1$
            computeNavImagePath(Messages.getString("SplittingHtmlDocumentBuilder.Previous_Image")));
        } else {
            out.link(linkAttributes, previous.getSplitTarget(), // $NON-NLS-1$
            Messages.getString("SplittingHtmlDocumentBuilder.Previous"));
        }
    }
    out.endBlock();
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("center");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 60%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (!header && !rootPage) {
        linkAttributes = new LinkAttributes();
        linkAttributes.setTitle(rootBuilder.getTitle());
        if (navigationImages) {
            ImageAttributes imageAttributes = new ImageAttributes();
            imageAttributes.setAlt(rootBuilder.getTitle());
            out.imageLink(linkAttributes, imageAttributes, rootFile.getName(), // $NON-NLS-1$
            computeNavImagePath(Messages.getString("SplittingHtmlDocumentBuilder.Home_Image")));
        } else {
            // $NON-NLS-1$
            out.link(linkAttributes, rootFile.getName(), Messages.getString("SplittingHtmlDocumentBuilder.Home"));
        }
    }
    out.endBlock();
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("right");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 20%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (next != null) {
        linkAttributes = new LinkAttributes();
        linkAttributes.setTitle(next.getLabel());
        if (navigationImages) {
            ImageAttributes imageAttributes = new ImageAttributes();
            // $NON-NLS-1$
            imageAttributes.setAlt(Messages.getString("SplittingHtmlDocumentBuilder.Next"));
            out.imageLink(linkAttributes, imageAttributes, next.getSplitTarget(), // $NON-NLS-1$
            computeNavImagePath(Messages.getString("SplittingHtmlDocumentBuilder.Next_Image")));
        } else {
            out.link(linkAttributes, next.getSplitTarget(), // $NON-NLS-1$
            Messages.getString("SplittingHtmlDocumentBuilder.Next"));
        }
    }
    out.endBlock();
    // navigation row
    out.endBlock();
    // navigation title row
    out.beginBlock(BlockType.TABLE_ROW, new Attributes());
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("left");
    // $NON-NLS-1$
    tableCellAttributes.setValign("top");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 20%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (previous != null) {
        out.characters(previous.getLabel());
    }
    out.endBlock();
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("center");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 60%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    out.endBlock();
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("right");
    // $NON-NLS-1$
    tableCellAttributes.setValign("top");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 20%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (next != null) {
        out.characters(next.getLabel());
    }
    out.endBlock();
    // navigation title row
    out.endBlock();
    // table
    out.endBlock();
    if (header) {
        // $NON-NLS-1$
        out.charactersUnescaped("<hr class=\"navigation-separator\"/>");
    }
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) TableCellAttributes(org.eclipse.mylyn.wikitext.parser.TableCellAttributes) TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes) TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes) ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) TableCellAttributes(org.eclipse.mylyn.wikitext.parser.TableCellAttributes)

Example 5 with TableAttributes

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

the class TableBlock method processBlockStart.

@Override
protected void processBlockStart() {
    if (startDelimiter.startsWith(",")) {
        // $NON-NLS-1$
        // ",===" is the shorthand notation for [format="csv", options="header"]
        format = TableFormat.COMMA_SEPARATED_VALUES;
        hasHeader = true;
    } else if (startDelimiter.startsWith(":")) {
        // $NON-NLS-1$
        // ":===" is the shorthand notation for [format="dsv", options="header"]
        format = TableFormat.DELIMITER_SEPARATED_VALUES;
        hasHeader = true;
    } else {
        // default table format is PSV with separator "|"
        format = TableFormat.PREFIX_SEPARATED_VALUES;
        // $NON-NLS-1$
        separator = "|";
    }
    Map<String, String> lastProperties = getAsciiDocState().getLastProperties(Collections.emptyList());
    // $NON-NLS-1$
    colsAttribute = LanguageSupport.computeColumnsAttributeList(lastProperties.get("cols"));
    // $NON-NLS-1$
    String formatProperty = lastProperties.get("format");
    if (formatProperty != null) {
        switch(formatProperty) {
            case // $NON-NLS-1$
            "dsv":
                format = TableFormat.DELIMITER_SEPARATED_VALUES;
                break;
            case // $NON-NLS-1$
            "csv":
                format = TableFormat.COMMA_SEPARATED_VALUES;
                break;
        }
    }
    // $NON-NLS-1$
    String separator = lastProperties.get("separator");
    if (separator != null) {
        this.separator = separator;
    }
    // $NON-NLS-1$
    String options = lastProperties.get("options");
    if (options != null) {
        // $NON-NLS-1$
        hasHeader = options.contains("header");
    }
    TableAttributes tableAttributes = new TableAttributes();
    // $NON-NLS-1$
    tableAttributes.setWidth(lastProperties.get("width"));
    builder.beginBlock(BlockType.TABLE, tableAttributes);
}
Also used : TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes)

Aggregations

TableAttributes (org.eclipse.mylyn.wikitext.parser.TableAttributes)6 TableCellAttributes (org.eclipse.mylyn.wikitext.parser.TableCellAttributes)3 Matcher (java.util.regex.Matcher)2 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)2 LinkAttributes (org.eclipse.mylyn.wikitext.parser.LinkAttributes)2 TableRowAttributes (org.eclipse.mylyn.wikitext.parser.TableRowAttributes)2 CharMatcher (com.google.common.base.CharMatcher)1 BlockType (org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType)1 ImageAttributes (org.eclipse.mylyn.wikitext.parser.ImageAttributes)1 ListAttributes (org.eclipse.mylyn.wikitext.parser.ListAttributes)1