🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

trix

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trix

A rich text editor for everyday writing

2.1.15
latest
Version published
Weekly downloads
212K
-1.28%
Maintainers
5
Weekly downloads
 
Created

What is trix?

Trix is a rich text editor for everyday writing. It is designed to provide a simple and intuitive interface for creating and editing text content, with support for formatting, embedding media, and more.

What are trix's main functionalities?

Basic Text Formatting

This feature allows users to apply basic text formatting such as bold, italic, and underline. The code sample demonstrates how to initialize the Trix editor and insert bold text.

document.addEventListener('trix-initialize', function(event) {
  var editor = event.target.editor;
  editor.insertString('Hello, world!');
  editor.activateAttribute('bold');
  editor.insertString(' This is bold text.');
});

Embedding Media

This feature allows users to embed media such as images and videos into the text editor. The code sample demonstrates how to handle file attachments and embed them as data URLs.

document.addEventListener('trix-attachment-add', function(event) {
  var attachment = event.attachment;
  if (attachment.file) {
    var reader = new FileReader();
    reader.onload = function() {
      attachment.setAttributes({ url: reader.result });
    };
    reader.readAsDataURL(attachment.file);
  }
});

Custom Toolbar Buttons

This feature allows users to add custom buttons to the Trix editor toolbar. The code sample demonstrates how to add a custom 'Strike' button to the toolbar.

document.addEventListener('trix-initialize', function(event) {
  var buttonHTML = '<button type="button" class="trix-button" data-trix-attribute="strike">Strike</button>';
  var toolbar = event.target.toolbarElement;
  toolbar.querySelector('.trix-button-group--text-tools').insertAdjacentHTML('beforeend', buttonHTML);
});

Other packages similar to trix

FAQs

Package last updated on 08 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts