Search in sources :

Example 6 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();
        if (matcher.group(1) != null) {
            // 0-offset matches may start with the "table. " prefix.
            Textile.configureAttributes(attributes, matcher, 2, true);
            offset = line.length();
        }
        builder.beginBlock(BlockType.TABLE, attributes);
    } else if (markupLanguage.isEmptyLine(line)) {
        setClosed(true);
        return 0;
    }
    ++blockLineCount;
    if (offset == line.length()) {
        return -1;
    }
    String textileLine = offset == 0 ? line : line.substring(offset);
    Matcher rowMatcher = TABLE_ROW_PATTERN.matcher(textileLine);
    if (!rowMatcher.find()) {
        setClosed(true);
        return 0;
    }
    {
        TableRowAttributes rowAttributes = new TableRowAttributes();
        int rowStart = rowMatcher.start();
        if (rowStart > 0) {
            // if the row content starts somewhere in the line then it's likely
            // that we have some row-level attributes
            Matcher rowAttributesMatcher = rowAttributesPattern.matcher(textileLine);
            if (rowAttributesMatcher.matches()) {
                Textile.configureAttributes(rowAttributes, rowAttributesMatcher, 1, true);
            }
        }
        builder.beginBlock(BlockType.TABLE_ROW, rowAttributes);
    }
    do {
        int start = rowMatcher.start();
        if (start == textileLine.length() - 1) {
            break;
        }
        String colSpan = rowMatcher.group(1);
        String rowSpan = rowMatcher.group(2);
        String alignment = rowMatcher.group(3);
        String headerIndicator = rowMatcher.group(8);
        String text = rowMatcher.group(9);
        int textLineOffset = rowMatcher.start(9);
        // $NON-NLS-1$ //$NON-NLS-2$
        boolean header = headerIndicator != null && ("_".equals(headerIndicator) || "|".equals(headerIndicator));
        String textAlign = null;
        if (alignment != null) {
            if (alignment.equals("<>")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                textAlign = "text-align: center;";
            } else if (alignment.equals(">")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                textAlign = "text-align: right;";
            } else if (alignment.equals("<")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                textAlign = "text-align: left;";
            } else if (alignment.equals("^")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                textAlign = "vertical-align: top;";
            }
        }
        TableCellAttributes attributes = new TableCellAttributes();
        attributes.setCssStyle(textAlign);
        attributes.setRowspan(rowSpan);
        attributes.setColspan(colSpan);
        Textile.configureAttributes(attributes, rowMatcher, 4, false);
        state.setLineCharacterOffset(start);
        builder.beginBlock(header ? BlockType.TABLE_CELL_HEADER : BlockType.TABLE_CELL_NORMAL, attributes);
        markupLanguage.emitMarkupLine(getParser(), state, textLineOffset, CharMatcher.WHITESPACE.trimTrailingFrom(text), 0);
        // table cell
        builder.endBlock();
    } while (rowMatcher.find());
    // table row
    builder.endBlock();
    return -1;
}
Also used : TableRowAttributes(org.eclipse.mylyn.wikitext.parser.TableRowAttributes) Matcher(java.util.regex.Matcher) CharMatcher(com.google.common.base.CharMatcher) TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes) TableCellAttributes(org.eclipse.mylyn.wikitext.parser.TableCellAttributes)

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