org.commonmark.node.Emphasis Java Examples

The following examples show how to use org.commonmark.node.Emphasis. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmphasisDelimiterProcessor.java    From 1Rramp-Android with MIT License 6 votes vote down vote up
@Override
public void process(Text opener, Text closer, int delimiterUse) {
    String singleDelimiter = String.valueOf(getOpeningCharacter());
    Node emphasis = delimiterUse == 1
            ? new Emphasis(singleDelimiter)
            : new StrongEmphasis(singleDelimiter + singleDelimiter);

    Node tmp = opener.getNext();
    while (tmp != null && tmp != closer) {
        Node next = tmp.getNext();
        emphasis.appendChild(tmp);
        tmp = next;
    }

    opener.insertAfter(emphasis);
}
 
Example #2
Source File: CorePlugin.java    From Markwon with Apache License 2.0 6 votes vote down vote up
@Override
public void configureSpansFactory(@NonNull MarkwonSpansFactory.Builder builder) {

    // reuse this one for both code-blocks (indent & fenced)
    final CodeBlockSpanFactory codeBlockSpanFactory = new CodeBlockSpanFactory();

    builder
            .setFactory(StrongEmphasis.class, new StrongEmphasisSpanFactory())
            .setFactory(Emphasis.class, new EmphasisSpanFactory())
            .setFactory(BlockQuote.class, new BlockQuoteSpanFactory())
            .setFactory(Code.class, new CodeSpanFactory())
            .setFactory(FencedCodeBlock.class, codeBlockSpanFactory)
            .setFactory(IndentedCodeBlock.class, codeBlockSpanFactory)
            .setFactory(ListItem.class, new ListItemSpanFactory())
            .setFactory(Heading.class, new HeadingSpanFactory())
            .setFactory(Link.class, new LinkSpanFactory())
            .setFactory(ThematicBreak.class, new ThematicBreakSpanFactory());
}
 
Example #3
Source File: EmphasisDelimiterProcessor.java    From commonmark-java with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void process(Text opener, Text closer, int delimiterUse) {
    String singleDelimiter = String.valueOf(getOpeningCharacter());
    Node emphasis = delimiterUse == 1
            ? new Emphasis(singleDelimiter)
            : new StrongEmphasis(singleDelimiter + singleDelimiter);

    Node tmp = opener.getNext();
    while (tmp != null && tmp != closer) {
        Node next = tmp.getNext();
        emphasis.appendChild(tmp);
        tmp = next;
    }

    opener.insertAfter(emphasis);
}
 
Example #4
Source File: MarkwonSpansFactoryImplTest.java    From Markwon with Apache License 2.0 5 votes vote down vote up
@Test
public void builder() {
    // all passed to builder will be in factory

    final SpanFactory text = mock(SpanFactory.class);
    final SpanFactory link = mock(SpanFactory.class);

    final MarkwonSpansFactory factory = new MarkwonSpansFactoryImpl.BuilderImpl()
            .setFactory(Text.class, text)
            .setFactory(Link.class, link)
            .build();

    assertNotNull(factory.get(Text.class));

    assertNotNull(factory.get(Link.class));

    // a bunch of non-present factories
    //noinspection unchecked
    final Class<? extends Node>[] types = new Class[]{
            Image.class,
            Block.class,
            Emphasis.class,
            Paragraph.class
    };

    for (Class<? extends Node> type : types) {
        assertNull(factory.get(type));
    }
}
 
Example #5
Source File: EmphasisHandler.java    From Markwon with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Object getSpans(
        @NonNull MarkwonConfiguration configuration,
        @NonNull RenderProps renderProps,
        @NonNull HtmlTag tag) {
    final SpanFactory spanFactory = configuration.spansFactory().get(Emphasis.class);
    if (spanFactory == null) {
        return null;
    }
    return spanFactory.getSpans(configuration, renderProps);
}
 
Example #6
Source File: MarkwonVisitorImpl.java    From Markwon with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(Emphasis emphasis) {
    visit((Node) emphasis);
}