Search in sources :

Example 61 with Attributes

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

the class HeadingBlock method processLineContent.

@Override
public int processLineContent(String line, int offset) {
    if (blockLineCount == 0) {
        Attributes attributes = new Attributes();
        if (offset == 0) {
            // 0-offset matches may start with the "hn. " prefix.
            level = Integer.parseInt(matcher.group(1));
            Textile.configureAttributes(attributes, matcher, 2, true);
            offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET);
        }
        if (attributes.getId() == null) {
            // $NON-NLS-1$
            attributes.setId(state.getIdGenerator().newId("h" + level, line.substring(offset)));
        }
        builder.beginHeading(level, attributes);
    }
    if (markupLanguage.isEmptyLine(line)) {
        setClosed(true);
        return 0;
    }
    if (blockLineCount != 0) {
        // $NON-NLS-1$
        getMarkupLanguage().emitMarkupText(getParser(), state, "\n");
    }
    ++blockLineCount;
    getMarkupLanguage().emitMarkupLine(getParser(), state, line, offset);
    return -1;
}
Also used : Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 62 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) {
    nestedStartOffset = -1;
    nestedLineNumber = -1;
    if (blockLineCount == 0) {
        Attributes attributes = new Attributes();
        builder.beginBlock(BlockType.PARAGRAPH, attributes);
    }
    if (markupLanguage.isEmptyLine(line)) {
        setClosed(true);
        return 0;
    }
    MediaWikiLanguage dialect = (MediaWikiLanguage) getMarkupLanguage();
    // paragraphs can have nested lists and other things
    for (Block block : dialect.getParagraphBreakingBlocks()) {
        if (block.canStart(line, offset)) {
            setClosed(true);
            return offset;
        }
    }
    nestedStartOffset = calculateNestedStartOffset(line, offset);
    if (nestedStartOffset != -1) {
        nestedLineNumber = getState().getLineNumber();
    }
    ++blockLineCount;
    if (testPreformattedBlocks && offset == 0 && line.length() > 0 && line.charAt(0) == ' ') {
        // a preformatted block.
        setClosed(true);
        return 0;
    }
    if (blockLineCount != 1 && nestedStartOffset == -1 && lastLineNumber != getState().getLineNumber()) {
        // note: normally newlines don't automatically convert to line breaks
        if (newlinesCauseLineBreak) {
            builder.lineBreak();
        } else {
            // $NON-NLS-1$
            builder.characters("\n");
        }
    }
    if (nestedStartOffset > 0) {
        line = line.substring(0, nestedStartOffset);
    }
    if (nestedStartOffset != offset) {
        dialect.emitMarkupLine(getParser(), state, line, offset);
    }
    lastLineNumber = getState().getLineNumber();
    return nestedStartOffset;
}
Also used : Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) MediaWikiLanguage(org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage) Block(org.eclipse.mylyn.wikitext.parser.markup.Block)

Example 63 with Attributes

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

the class AttributesTest method testClone.

@Test
public void testClone() {
    Attributes original = new Attributes("1", "class", "style", "lang");
    Attributes copy = original.clone();
    assertNotNull(copy);
    assertEquals(original.getId(), copy.getId());
    assertEquals(original.getCssClass(), copy.getCssClass());
    assertEquals(original.getCssStyle(), copy.getCssStyle());
    assertEquals(original.getLanguage(), copy.getLanguage());
}
Also used : Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) Test(org.junit.Test)

Example 64 with Attributes

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

the class HtmlDocumentBuilderTest method buildBasicDocument.

protected void buildBasicDocument() {
    builder.beginDocument();
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    builder.characters("test");
    builder.endBlock();
    builder.endDocument();
}
Also used : Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes)

Example 65 with Attributes

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

the class HtmlDocumentBuilderTest method cssClassesAreAppliedToNestedElements.

@Test
public void cssClassesAreAppliedToNestedElements() {
    Attributes attributes = new Attributes();
    attributes.setCssClass("aclass");
    builder.setEmitAsDocument(false);
    builder.beginDocument();
    builder.beginBlock(BlockType.CODE, attributes);
    builder.characters("content");
    builder.endBlock();
    builder.endDocument();
    assertEquals("<pre class=\"aclass\"><code class=\"aclass\">content</code></pre>", out.toString());
}
Also used : Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes) Test(org.junit.Test)

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