4,926
stars
414
forks
97
watchers
128
prs
366
issues
0
releases
0
discussions
README
Squire
Squire is an HTML5 rich text editor, which provides powerful cross-browser normalisation in a flexible lightweight package (only 16KB of JS after minification and gzip, with no dependencies!).
It was designed to handle email composition for the Fastmail web app. The most important consequence of this (and where Squire differs from most other modern rich text editors) is that it must handle arbitrary HTML, because it may be used to forward or quote emails from third-parties and must be able to preserve their HTML without breaking the formatting. This means that it can't use a more structured (but limited) internal data model (as most other modern HTML editors do) and the HTML remains the source-of-truth. The other consequence is excellent handling of multiple levels of blockquotes.
Squire is designed to be integrated with your own UI framework, and so does not provide its own UI toolbar, widgets or overlays. Instead, you get a component you can insert in place of a and manipulate programmatically, allowing you to integrate seamlessly with the rest of your application and lose the bloat of having two UI toolkits loaded.
Squire supports all reasonably recent browsers. It no longer supports any version of IE.
In addition to its use at Fastmail, it is also currently used in production at ProtonMail, SnappyMail, StartMail, Tutanota, Zoho Mail, Superhuman and Teamwork Desk, as well as other non-mail apps including Google Earth (drop me a line if you're using Squire elsewhere, I'm always interested to hear about it!).
For a demo of the latest version with a production-level UI integration, sign up for a free Fastmail trial :). There's also a very bare-bones integration in the repo; just clone it and open Demo.html. If you are reporting a bug, please report the steps to reproduce using Demo.html, to make sure it's not a bug in your integration.
Installation and usage
1. Add Squire to your project: npm install squire-rte
2. In your code, import Squire from 'squire-rte';
3. Create your editor by calling editor = new Squire(node);.
Invoke with script tag
Squire can also be used in a script tag:
1. Add a tag to load in dist/squire.js (or squire-raw.js for the debuggable unminified version):
2. Get a reference to the DOM node in the document that you want to make into the rich textarea, e.g. node = document.getElementById('editor-div').
3. Call editor = new Squire(node). This will instantiate a new Squire instance. Please note, this will remove any current children of the node; you must use the setHTML command after initialising to set any content.
Editor lifecycle
You can have multiple Squire instances in a single page without issue. If you are using the editor as part of a long lived single-page app, be sure to call editor.destroy() once you have finished using an instance to ensure it doesn't leak resources.
Security
Malicious HTML can be a source of XSS and other security issues. You MUST provide a method to safely convert Top issues
#438Blockmodification always inserts br after block4 comments · 2023-09-20#415Inserted HTML <button> gets immediately removed4 comments · 2021-08-13#412Additional line breaks - creates extra spacing in HTML4 comments · 2021-06-03#409Block vs Inline level elements and br tags4 comments · 2021-05-17#327Various dysfunctional behaviors when using with shadow DOM (potential fix)4 comments · 2018-08-15#351Placeholder support?3 comments · 2019-04-18#277Deleting a horizontal rule from editor doesn't work properly or at all3 comments · 2017-04-20#472[Feature] contenteditable="false" Inline Elements2 comments · 2024-11-25