Search in sources :

Example 91 with Attributes

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

the class TextileDocumentBuilderTest method testBulletedList.

public void testBulletedList() {
    builder.beginDocument();
    builder.beginBlock(BlockType.BULLETED_LIST, new Attributes());
    builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
    builder.characters("text2");
    builder.beginSpan(SpanType.BOLD, new Attributes());
    builder.characters("text3");
    builder.endSpan();
    builder.endBlock();
    emitListItem("text4");
    builder.endBlock();
    builder.endDocument();
    String markup = out.toString();
    assertEquals("* text2 **text3**\n* text4\n", markup);
}
Also used : ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 92 with Attributes

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

the class ListBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    boolean continuation = false;
    if (blockLineCount == 0) {
        listState = new Stack<>();
        Attributes attributes = new Attributes();
        String listSpec = matcher.group(1);
        int level = calculateLevel(listSpec);
        String typeSpec = matcher.group(2);
        BlockType type = calculateType(typeSpec);
        computeAttributes(attributes, type, typeSpec);
        // 0-offset matches may start with the "*** " prefix.
        offset = matcher.start(3);
        listState.push(new ListState(1, type));
        builder.beginBlock(type, attributes);
        adjustLevel(type, listSpec, level);
    } else {
        Matcher matcher = startPattern.matcher(line);
        if (!matcher.matches()) {
            // FIXME: continuations not yet implemented
            matcher = continuationPattern.matcher(line);
            if (listState.isEmpty() || !matcher.matches()) {
                setClosed(true);
                return 0;
            } else {
                continuation = true;
                // use -1 to get one whitespace character
                offset = matcher.start(1) - 1;
            }
        } else {
            String listSpec = matcher.group(1);
            int level = calculateLevel(listSpec);
            String typeSpec = matcher.group(2);
            BlockType type = calculateType(typeSpec);
            offset = matcher.start(3);
            adjustLevel(type, typeSpec, level);
        }
    }
    ++blockLineCount;
    ListState listState = this.listState.peek();
    if (!continuation && listState.openItem) {
        builder.endBlock();
        listState.openItem = false;
    }
    if (!listState.openItem) {
        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) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 93 with Attributes

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

the class ParagraphBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    if (blockLineCount == 0) {
        Attributes attributes = new Attributes();
        builder.beginBlock(BlockType.PARAGRAPH, attributes);
    }
    if (markupLanguage.isEmptyLine(line)) {
        setClosed(true);
        return 0;
    }
    TWikiLanguage textileLanguage = (TWikiLanguage) getMarkupLanguage();
    for (Block block : textileLanguage.getParagraphBreakingBlocks()) {
        if (block.canStart(line, offset)) {
            setClosed(true);
            return 0;
        }
    }
    if (blockLineCount != 0) {
        builder.lineBreak();
    }
    ++blockLineCount;
    textileLanguage.emitMarkupLine(getParser(), state, line, offset);
    return -1;
}
Also used : TWikiLanguage(org.eclipse.mylyn.wikitext.twiki.TWikiLanguage) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) Block(org.eclipse.mylyn.wikitext.parser.markup.Block)

Example 94 with Attributes

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

the class TextileTest method testJustifiedAlignment.

public void testJustifiedAlignment() {
    Pattern pattern = Pattern.compile("h1" + Textile.REGEX_BLOCK_ATTRIBUTES + "\\. (.*)?");
    Matcher matcher = pattern.matcher("h1<>. foo");
    assertTrue(matcher.matches());
    Attributes attributes = new Attributes();
    Textile.configureAttributes(attributes, matcher, 1, true);
    assertEquals("text-align: justify;", attributes.getCssStyle());
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 95 with Attributes

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

the class TextileTest method testRightPadding.

public void testRightPadding() {
    Pattern pattern = Pattern.compile("h1" + Textile.REGEX_BLOCK_ATTRIBUTES + "\\. (.*)?");
    Matcher matcher = pattern.matcher("h1))). foo");
    assertTrue(matcher.matches());
    Attributes attributes = new Attributes();
    Textile.configureAttributes(attributes, matcher, 1, true);
    assertEquals("padding-right: 3em;", attributes.getCssStyle());
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

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