https://github.com/hopsoft/trix_embed
Take control over what external links and embedded media is permitted in the Trix editor via copy/paste
https://github.com/hopsoft/trix_embed
actiontext stimulus trix trix-editor wysiwyg
Last synced: 5 months ago
JSON representation
Take control over what external links and embedded media is permitted in the Trix editor via copy/paste
- Host: GitHub
- URL: https://github.com/hopsoft/trix_embed
- Owner: hopsoft
- License: mit
- Created: 2023-08-04T06:20:02.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-04T18:36:16.000Z (about 2 years ago)
- Last Synced: 2025-04-10T02:37:59.324Z (10 months ago)
- Topics: actiontext, stimulus, trix, trix-editor, wysiwyg
- Language: JavaScript
- Homepage:
- Size: 201 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# Trix Embed
#### Take control over what external links and embedded media is permitted in the Trix editor via copy/paste
## Table of Contents
- [Dependencies](#dependencies)
- [Setup](#setup)
- [Features](#features)
- [Allow / Block Lists](#allow--block-lists)
- [Template Overrides](#template-overrides)
- [Basic Usage](#basic-usage)
- [Allow Lists](#allow-lists)
- [Block Lists](#block-lists)
- [Persistence](#persistence)
- [Sponsors](#sponsors)
- [Developing](#developing)
- [Releasing](#releasing)
- [License](#license)
## Dependencies
- [ActionText](https://github.com/rails/rails/tree/main/actiontext)
- [Stimulus](https://github.com/hotwired/stimulus)
- [Trix](https://github.com/basecamp/trix)
## Setup
```sh
bundle add trix_embed
yarn add trix-embed@$(bundle show trix_embed | ruby -ne 'puts $_.split(/-/).last')
```
```js
import Trix from 'trix'
import "@rails/actiontext"
import { Application, Controller } from '@hotwired/stimulus'
import TrixEmbed from 'trix-embed'
const application = Application.start()
TrixEmbed.initialize({ application, Controller, Trix })
```
## Features
### Allow / Block Lists
Configure allow and/or block lists for external links and embedded media in your Trix editors.
__⚠︎ Block lists have precendence!__
- allowed link hosts
- blocked link hosts
- allowed media hosts
- blocked media hosts
_Note that you can also use wildcards `*` in any of lists._
### Template Overrides
TODO: document...
## Basic Usage
### Allow Lists
- Allow everything
```html
```
- Allow links to all hosts and allow media (images, videos, etc.) from the following hosts: `vimeo.com, voomly.com, youtube.com`
```html
```
### Block Lists
- Block everything
```html
```
...or simply.
```html
```
- Block links to the following hosts: `4chan.org, 8chan.net, thepiratebay.org`
and block media (images, videos, etc.) from the following hosts: `deviantart.com, imgur.com, tumblr.com`
```html
```
## Persistence
You'll need to ensure any embedded attachments are prepared for persistence.
```ruby
class ContentController < ApplicationController
def create
Example.create content: TrixEmbed::Attachment.rewrite_for_storage(params[:content].to_s)
end
end
```
## Sponsors
Proudly sponsored by
## Developing
```sh
git clone https://github.com/hopsoft/trix_embed.git
cd trix_embed
bin/dev
```
## Releasing
1. Run `yarn` and `bundle` to pick up the latest
1. Bump version number at `lib/trix_embed/version.rb`. Pre-release versions use `.preN`
1. Bump version number at `package.json` _(make sure it matches)_. Pre-release versions use `-preN`
1. Run `yarn build` - *builds both the Ruby gem and the NPM package*
1. Commit and push changes to GitHub
1. Run `rake release`
1. Run `yarn publish --no-git-tag-version --access public --new-version X.X.X` _(use same version number)_
1. Create a new release on GitHub ([here](https://github.com/hopsoft/trix_embed/releases)) and generate the changelog for the stable release for it
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).