Search in sources :

Example 56 with Attributes

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

the class PreformattedBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    int lineStart = usesTag ? 0 : 1;
    if (blockLineCount++ == 0) {
        Attributes attributes = new Attributes();
        if (usesTag) {
            Matcher matcher = PRE_OPEN_PATTERN.matcher(line);
            if (offset > 0) {
                matcher.region(offset, line.length());
            }
            if (matcher.matches()) {
                String htmlAttributes = matcher.group(2);
                processHtmlAttributes(attributes, htmlAttributes);
                lineStart = matcher.end(1);
                offset = lineStart;
            } else {
                throw new IllegalStateException();
            }
        }
        builder.beginBlock(BlockType.PREFORMATTED, attributes);
    }
    if (usesTag) {
        if (blockLineCount > 0) {
            Matcher closeMatcher = PRE_CLOSE_PATTERN.matcher(line);
            if (offset > 0) {
                closeMatcher.region(offset, line.length());
            }
            if (closeMatcher.find()) {
                int contentEnd = closeMatcher.start(1);
                int newContentStart = closeMatcher.end(1);
                if (contentEnd > 0) {
                    addContent(line.substring(0, contentEnd), offset);
                }
                setClosed(true);
                if (newContentStart < line.length()) {
                    return newContentStart;
                }
                return -1;
            }
        }
    } else {
        if (markupLanguage.isEmptyLine(line) || (offset == 0 && line.charAt(0) != ' ')) {
            setClosed(true);
            return 0;
        }
    }
    if (line.length() >= lineStart) {
        addContent(line, lineStart);
    }
    return -1;
}
Also used : Matcher(java.util.regex.Matcher) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 57 with Attributes

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

the class DitaTopicDocumentBuilderTest method testDiv.

public void testDiv() {
    builder.beginDocument();
    builder.beginBlock(BlockType.DIV, new Attributes());
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    builder.characters("foo");
    // PARAGRAPH
    builder.endBlock();
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    builder.characters("bar");
    // PARAGRAPH
    builder.endBlock();
    // DIV
    builder.endBlock();
    builder.endDocument();
    String dita = out.toString();
    assertTrue(Pattern.compile(".*?<topic>\\s*<title></title>\\s*<body>\\s*<p>foo</p>\\s*<p>bar</p>\\s*</body>.*", Pattern.DOTALL).matcher(dita).matches());
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 58 with Attributes

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

the class TextileDocumentBuilder method computeSpan.

@Override
protected Block computeSpan(SpanType type, Attributes attributes) {
    String appendStyle = null;
    switch(type) {
        case UNDERLINED:
            // $NON-NLS-1$
            appendStyle = "text-decoration:underline;";
            break;
        case MONOSPACE:
            // $NON-NLS-1$
            appendStyle = "font-family:monospace;";
            break;
    }
    if (appendStyle != null) {
        attributes = new Attributes(attributes.getId(), attributes.getCssClass(), attributes.getCssStyle(), attributes.getLanguage());
        attributes.appendCssStyle(appendStyle);
    }
    Block block;
    String spanAttributes = computeAttributes(attributes);
    switch(type) {
        case BOLD:
            // $NON-NLS-1$//$NON-NLS-2$
            block = new ContentBlock("**" + spanAttributes, "**", true, false, 0, 0);
            break;
        case CITATION:
            // $NON-NLS-1$//$NON-NLS-2$
            block = new ContentBlock("??" + spanAttributes, "??", true, false, 0, 0);
            break;
        case DELETED:
            // $NON-NLS-1$//$NON-NLS-2$
            block = new ContentBlock("-" + spanAttributes, "-", true, false, 0, 0);
            break;
        case MARK:
        case EMPHASIS:
            // $NON-NLS-1$//$NON-NLS-2$
            block = new ContentBlock("_" + spanAttributes, "_", true, false, 0, 0);
            break;
        case INSERTED:
            // $NON-NLS-1$//$NON-NLS-2$
            block = new ContentBlock("+" + spanAttributes, "+", true, false, 0, 0);
            break;
        case CODE:
            // $NON-NLS-1$//$NON-NLS-2$
            block = new ContentBlock("@" + spanAttributes, "@", true, false, 0, 0);
            break;
        case ITALIC:
            // $NON-NLS-1$//$NON-NLS-2$
            block = new ContentBlock("__" + spanAttributes, "__", true, false, 0, 0);
            break;
        case LINK:
            if (attributes instanceof LinkAttributes) {
                block = new LinkBlock((LinkAttributes) attributes);
            } else {
                block = new SpanBlock(spanAttributes, true, false);
            }
            break;
        case MONOSPACE:
            block = new SpanBlock(spanAttributes, true, false);
            break;
        case STRONG:
            // $NON-NLS-1$//$NON-NLS-2$
            block = new ContentBlock("*" + spanAttributes, "*", true, false, 0, 0);
            break;
        case SUPERSCRIPT:
            // $NON-NLS-1$//$NON-NLS-2$
            block = new ContentBlock("^" + spanAttributes, "^", true, false, 0, 0);
            break;
        case SUBSCRIPT:
            // $NON-NLS-1$//$NON-NLS-2$
            block = new ContentBlock("~" + spanAttributes, "~", true, false, 0, 0);
            break;
        // case QUOTE: not supported by Textile
        case UNDERLINED:
        case SPAN:
        default:
            if (spanAttributes.length() == 0) {
                // $NON-NLS-1$
                block = new SpanBlock("", true, false);
            } else {
                block = new SpanBlock(spanAttributes, true, false);
            }
            break;
    }
    return block;
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 59 with Attributes

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

the class CodeBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    if (blockLineCount == 0) {
        Attributes attributes = new Attributes();
        Textile.configureAttributes(attributes, matcher, 1, true);
        offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET);
        extended = matcher.group(EXTENDED_GROUP) != null;
        builder.beginBlock(BlockType.CODE, attributes);
    }
    if (markupLanguage.isEmptyLine(line) && !extended) {
        setClosed(true);
        return 0;
    } else if (extended && Textile.explicitBlockBegins(line, offset)) {
        setClosed(true);
        return offset;
    }
    ++blockLineCount;
    final String lineText = offset > 0 ? line.substring(offset) : line;
    if (blockLineCount > 1 || lineText.trim().length() > 0) {
        builder.characters(lineText);
        // $NON-NLS-1$
        builder.characters("\n");
    }
    return -1;
}
Also used : Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 60 with Attributes

use of org.eclipse.mylyn.wikitext.parser.Attributes 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)

Aggregations

Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)428 LinkAttributes (org.eclipse.mylyn.wikitext.parser.LinkAttributes)248 ImageAttributes (org.eclipse.mylyn.wikitext.parser.ImageAttributes)223 Test (org.junit.Test)176 Matcher (java.util.regex.Matcher)33 ListAttributes (org.eclipse.mylyn.wikitext.parser.ListAttributes)29 TableAttributes (org.eclipse.mylyn.wikitext.parser.TableAttributes)17 StringWriter (java.io.StringWriter)14 BlockType (org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType)12 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)10 Pattern (java.util.regex.Pattern)9 DocumentBuilder (org.eclipse.mylyn.wikitext.parser.DocumentBuilder)9 SpanStrategies (org.eclipse.mylyn.wikitext.html.internal.SpanStrategies)8 Block (org.eclipse.mylyn.wikitext.parser.markup.Block)8 SpanStrategy (org.eclipse.mylyn.wikitext.html.internal.SpanStrategy)6 SubstitutionBlockStrategy (org.eclipse.mylyn.wikitext.html.internal.SubstitutionBlockStrategy)6 SubstitutionSpanStrategy (org.eclipse.mylyn.wikitext.html.internal.SubstitutionSpanStrategy)6 SubstitutionWithoutCssSpanStrategy (org.eclipse.mylyn.wikitext.html.internal.SubstitutionWithoutCssSpanStrategy)6 TableCellAttributes (org.eclipse.mylyn.wikitext.parser.TableCellAttributes)6 EventDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder)6