Custom block

This example shows how to create a simple inline block for Redactor.

Code

<style>
[data-block=tag] {
    background: var(--rx-fg-light-accent);
    font-size: 0.875em;
    padding: 3px 6px;
    border-radius: 6px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1), 0 3px 0 rgba(0, 0, 0, 0.1);
}
[rx-data-theme=dark] {
    [data-block=tag] {
        box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1), 0 3px 0 rgba(0, 0, 0, 0.1);
    }
}
</style>

<!-- element -->
<textarea id="entry">
    ... <span data-block="tag">Tag</span> ...
</textarea>

<!-- call -->
<script>
// custom block
Redactor.add('block', 'tag', {
    mixins: ['block'],
    props: {
        type: 'tag',
        editable: true,
        control: false,
        inline: true
    },
    defaults: {
        content: { getter: 'getContent', setter: 'setContent' }
    },
    create: function() {
        return this.dom('<span>').attr('data-block', 'tag');
    }
});

let app = Redactor('#entry');
</script>