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

com.vladsch.flexmark.ext.emoji.internal.EmojiJiraRenderer 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.html.CustomNodeRenderer;
import com.vladsch.flexmark.html.HtmlWriter;
import com.vladsch.flexmark.html.renderer.NodeRenderer;
import com.vladsch.flexmark.html.renderer.NodeRendererContext;
import com.vladsch.flexmark.html.renderer.NodeRendererFactory;
import com.vladsch.flexmark.html.renderer.NodeRenderingHandler;
import com.vladsch.flexmark.util.data.DataHolder;

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

public class EmojiJiraRenderer implements NodeRenderer {
    public static final HashMap shortCutMap = new HashMap();
    static {
        shortCutMap.put("smile", ":)");
        shortCutMap.put("frowning", ":(");
        shortCutMap.put("stuck_out_tongue", ":P");
        shortCutMap.put("grinning", ":D");
        shortCutMap.put("wink", ";)");
        shortCutMap.put("thumbsup", "(y)");
        shortCutMap.put("thumbsdown", "(n)");
        shortCutMap.put("information_source", "(i)");
        shortCutMap.put("white_check_mark", "(/)");
        shortCutMap.put("x", "(x)");
        shortCutMap.put("warning", "(!)");
        shortCutMap.put("heavy_plus_sign", "(+)");
        shortCutMap.put("heavy_minus_sign", "(-)");
        shortCutMap.put("question", "(?)");
        shortCutMap.put("bulb", "(on)");
        shortCutMap.put("star", "(*)");
        shortCutMap.put("triangular_flag_on_post", "(flag)");
        shortCutMap.put("crossed_flags", "(flagoff)");
    }
    public EmojiJiraRenderer(DataHolder options) {
    }

    @Override
    public Set> getNodeRenderingHandlers() {
        HashSet> set = new HashSet>();
        set.add(new NodeRenderingHandler(Emoji.class, new CustomNodeRenderer() {
            @Override
            public void render(Emoji node, NodeRendererContext context, HtmlWriter html) {
                EmojiJiraRenderer.this.render(node, context, html);
            }
        }));
        return set;
    }

    private void render(Emoji node, NodeRendererContext context, HtmlWriter html) {
        Emoji emoji = (Emoji) node;
        String shortcut = shortCutMap.get(emoji.getText().toString());
        if (shortcut == null) {
            // output as text
            html.text(":");
            context.renderChildren(node);
            html.text(":");
        } else {
            html.raw(shortcut);
        }
    }

    public static class Factory implements NodeRendererFactory {
        @Override
        public NodeRenderer apply(DataHolder options) {
            return new EmojiJiraRenderer(options);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy