All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vladsch.flexmark.ext.emoji.internal.EmojiNodeFormatter Maven / Gradle / Ivy

Go to download

flexmark-java extension for emoji shortcuts using Emoji-Cheat-Sheet.com http://www.emoji-cheat-sheet.com/

There is a newer version: 0.64.8
Show newest version
package com.vladsch.flexmark.ext.emoji.internal;

import com.vladsch.flexmark.ext.emoji.Emoji;
import com.vladsch.flexmark.formatter.*;
import com.vladsch.flexmark.util.data.DataHolder;

import java.util.HashSet;
import java.util.Set;

public class EmojiNodeFormatter implements NodeFormatter {

    public EmojiNodeFormatter(DataHolder options) {

    }

    @Override
    public Set> getNodeClasses() {
        return null;
    }

    // only registered if assignTextAttributes is enabled
    @Override
    public Set> getNodeFormattingHandlers() {
        HashSet> set = new HashSet>();
        set.add(new NodeFormattingHandler(Emoji.class, new CustomNodeFormatter() {
            @Override
            public void render(Emoji node, NodeFormatterContext context, MarkdownWriter markdown) {
                EmojiNodeFormatter.this.render(node, context, markdown);
            }
        }));
        return set;
    }

    void render(Emoji node, NodeFormatterContext context, MarkdownWriter markdown) {
        markdown.append(node.getOpeningMarker());
        markdown.appendNonTranslating(node.getText());
        markdown.append(node.getClosingMarker());
    }

    public static class Factory implements NodeFormatterFactory {
        @Override
        public NodeFormatter create(DataHolder options) {
            return new EmojiNodeFormatter(options);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy