Trix - amssdias/multitenant-blog-platform GitHub Wiki

Trix Usage in Multitenant Blog

Overview

This blog project uses Trix Editor to provide rich-text editing capabilities for blog posts. Trix is a lightweight, WYSIWYG editor built by Basecamp that outputs clean HTML, making it ideal for storing and rendering user-generated content in blogs.

Why Trix?

  • Lightweight and easy to integrate
  • Outputs clean HTML
  • Built-in support for formatting (bold, italic, links, lists, etc.)
  • Secure by default (no inline JS)

How It's Integrated

1. Installation

Trix is added to the frontend via a package manager or CDN:

<link rel="stylesheet" href="https://unpkg.com/trix/dist/trix.css">
<script src="https://unpkg.com/trix/dist/trix.js"></script>

2. HTML Integration

To use the Trix editor on a blog post form:

<form method="post" action="/posts">
  <input id="post_content" type="hidden" name="post[content]">
  <trix-editor input="post_content"></trix-editor>
</form>

3. Backend Handling

  • The post[content] field receives the Trix HTML output.
  • This content is stored as-is in the database (usually as HTML-safe text).

Multitenancy Notes

Each tenant uses the same Trix configuration. However, we can:

  • Override Trix CSS per-tenant for branding
  • Add tenant-specific extensions (e.g. custom embeds or toolbars)

Additional Customizations

  • Toolbar: Custom tools or buttons can be added by modifying the Trix toolbar.
  • Events: Trix emits events like trix-change, trix-attachment-add for advanced use.
  • Sanitization: Consider using HTML sanitizers server-side (e.g. sanitize-html, Loofah, etc.) to ensure saved content is safe.

Useful Links

⚠️ **GitHub.com Fallback** ⚠️