Problems with trix sanitization
- Dominant language
- JavaScript
- Stars
- 20k
- Forks
- 1.1k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 13
Description
I have a little problem using trix... I created a new feature to add a button for align-center, align-right and align-left. The problem I face is sanitization in the trix editor.
`import { Controller } from "@hotwired/stimulus";
import * as AlignmentElements from "../alignment_elements";
export default class TrixController extends Controller {
static targets = ['editor']
connect() {
this.initTrix()
}
initTrix () {
window.Trix = Trix; // Don't need to bind to the window, but useful for debugging.
Trix.config.toolbar.getDefaultHTML = toolbarDefaultHTML;
Trix.config.blockAttributes.alignLeft = {
tagName: 'align-left',
parse: false,
nestable: false,
exclusive: true,
};
Trix.config.blockAttributes.alignCenter = {
tagName: 'align-center',
parse: false,
nestable: false,
exclusive: true,
};
Trix.config.blockAttributes.alignRight = {
tagName: 'align-right',
parse: false,
nestable: false,
exclusive: true,
};
document.addEventListener('trix-initialize', updateToolbars, { once: true });
function updateToolbars(event) {
const toolbars = document.querySelectorAll('trix-toolbar');
const html = Trix.config.toolbar.getDefaultHTML();
toolbars.forEach((toolbar) => (toolbar.innerHTML = html));
}
/**
* This is the default Trix toolbar. Feel free to change / manipulate it how you would like.
* @see https://github.com/basecamp/trix/blob/main/src/trix/config/toolbar.coffee
*/
function toolbarDefaultHTML() {
const { lang } = Trix.config;
return `
`;
}
}
}`
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the sanitization behavior with the custom alignment elements from the issue and inspect the imported alignment_elements module alongside Trix's sanitization entry points. Determine which alignment markup is removed and define done as preserving the intended alignment output without weakening sanitization for other content.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100