Search in sources :

Example 1 with Attributes

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

the class ListBlock method adjustLevel.

private void adjustLevel(Matcher matcher, BlockType type, String tag) {
    // find correct level for next list item
    // default is next level
    int level = listState.size() + 1;
    for (ListState ls : listState) {
        if (ls.tag.equals(tag)) {
            // tag already used: drop to that level
            level = ls.level;
        }
    }
    for (ListState prevState = listState.peek(); level != prevState.level || prevState.type != type; prevState = listState.peek()) {
        if (level > prevState.level) {
            if (!prevState.openItem) {
                builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
                prevState.openItem = true;
            }
            ListAttributes attributes = new ListAttributes();
            if (type == BlockType.NUMERIC_LIST) {
                updateStyleAttribute(attributes, tag, null);
            }
            listState.push(new ListState(tag, prevState.level + 1, type));
            builder.beginBlock(type, attributes);
        } else {
            closeOne();
            if (listState.isEmpty()) {
                ListAttributes attributes = new ListAttributes();
                listState.push(new ListState(tag, 1, type));
                builder.beginBlock(type, attributes);
            }
        }
    }
}
Also used : ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes)

Example 2 with Attributes

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

the class ListBlock method processLineContent.

/**
 * AsciiDoc line process with given offset.
 */
@Override
protected int processLineContent(String line, int offset) {
    boolean closeItem = true;
    // first line processed in current block
    if (blockLineCount == 0) {
        listState = new Stack<>();
        ListAttributes attributes = new ListAttributes();
        String listSpec = normalizeListSpec(matcher.group(1));
        BlockType type = calculateType(listSpec);
        if (type == BlockType.NUMERIC_LIST) {
            List<String> positionalParameters = new ArrayList<>();
            positionalParameters.add(PARAM_NAME_STYLE);
            Map<String, String> lastProperties = getAsciiDocState().getLastProperties(positionalParameters);
            getAsciiDocState().setLastPropertiesText("");
            String startProperty = lastProperties.get(PARAM_NAME_START);
            if (startProperty != null) {
                attributes.setStart(startProperty);
            }
            String styleProperty = lastProperties.get(PARAM_NAME_STYLE);
            updateStyleAttribute(attributes, listSpec, styleProperty);
        }
        // first line of the block could be "** " or more
        offset = matcher.start(2);
        listState.push(new ListState(listSpec, 1, type));
        builder.beginBlock(type, attributes);
        adjustLevel(matcher, type, listSpec);
    } else if (line.isEmpty()) {
        if (!listContinuation) {
            blankSeparator = true;
        }
        return -1;
    } else if (isListContinuation(line)) {
        // list continuation
        blankSeparator = false;
        listContinuation = true;
        closeItem = false;
        return -1;
    } else {
        Matcher matcher = startPattern.matcher(line);
        if (!matcher.matches()) {
            if (blankSeparator) {
                setClosed(true);
                blankSeparator = false;
                return 0;
            }
            closeItem = false;
            Matcher leadingBlankMatcher = leadingBlankPattern.matcher(line);
            if (leadingBlankMatcher.find()) {
                offset = leadingBlankMatcher.end();
            }
            // $NON-NLS-1$
            markupLanguage.emitMarkupText(getParser(), state, " ");
        } else {
            String listSpec = normalizeListSpec(matcher.group(1));
            BlockType type = calculateType(listSpec);
            offset = matcher.start(2);
            adjustLevel(matcher, type, listSpec);
        }
        blankSeparator = false;
        listContinuation = false;
    }
    ++blockLineCount;
    ListState listState = this.listState.peek();
    if (closeItem) {
        if (listState.openItem) {
            builder.endBlock();
        }
        listState.openItem = true;
        builder.beginBlock(BlockType.LIST_ITEM, new Attributes());
    }
    markupLanguage.emitMarkupLine(getParser(), state, line, offset);
    // entire line processed
    return -1;
}
Also used : BlockType(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType) Matcher(java.util.regex.Matcher) ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes) ArrayList(java.util.ArrayList) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) ListAttributes(org.eclipse.mylyn.wikitext.parser.ListAttributes)

Example 3 with Attributes

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

the class CssClassPhraseModifier method newProcessor.

@Override
protected PatternBasedElementProcessor newProcessor() {
    return new PatternBasedElementProcessor() {

        @Override
        public void emit() {
            Attributes attributes = new Attributes();
            SpanType span = SpanType.SPAN;
            String cssClass = group(1);
            if (cssClass != null && !cssClass.isEmpty()) {
                attributes.setCssClass(cssClass);
            } else {
                span = SpanType.MARK;
            }
            getBuilder().beginSpan(span, attributes);
            getBuilder().characters(group(2));
            getBuilder().endSpan();
        }
    };
}
Also used : SpanType(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.SpanType) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) PatternBasedElementProcessor(org.eclipse.mylyn.wikitext.parser.markup.PatternBasedElementProcessor)

Example 4 with Attributes

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

the class AsciiDocDocumentBuilderTest method testSpan.

@Test
public void testSpan() {
    builder.beginDocument();
    builder.characters("prefix ");
    builder.beginSpan(SpanType.BOLD, new Attributes());
    builder.characters("bold");
    builder.endSpan();
    builder.characters(" suffix");
    builder.endDocument();
    assertMarkup("prefix *bold* suffix\n\n");
}
Also used : ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) Test(org.junit.Test)

Example 5 with Attributes

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

the class AsciiDocDocumentBuilderTest method testImplicitParagraph.

@Test
public void testImplicitParagraph() {
    builder.beginDocument();
    builder.characters("text1");
    builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
    builder.characters("text2");
    builder.endBlock();
    builder.characters("text3");
    builder.endDocument();
    assertMarkup("text1\n\ntext2\n\ntext3\n\n");
}
Also used : ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) 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