WriteFree is a simple and clutter-free embeddable rich text editor. Drawing its design from Medium's beautiful editor, WriteFree allows you to offer users a beautiful and immersive writing experience in any environment or setting.
WriteFree features all that's needed to create a masterpiece and nothing more. The idea is to get out of the writer's way and let them focus on what they're working on while still being there for them to add basic styles and insertable elements as necessary.
Users will find all the editing tools they need and none that they don't. Highlighting a selection of text brings up the Edit Toolbar. This toolbar allows users to bold and italicize text, turn their selection into two varieties of headings (via <h1> and <h2> elements), and wrap selections of text in a hyperlink.
WriteFree allows users to insert images and horizontal rules into their text via the Insert Toolar. The Insert Toolbar can be brought up by selecting or creating an empty line in the editor. As of now, users need the public-facing URL for any images they would like to insert.
Using WriteFree in your next project is an easy affair. With one line of JavaScript you have a fully-featured yet easy-to-use text editor ready for your users.
First, grab WriteFree from the jsDelivr CDN:
<script crossorigin src="https://cdn.jsdelivr.net/npm/writefree@1.2.12/build/js/writefree.min.js" type="text/javascript"></script>
Create a div to use as a container for WriteFree:
<div id="wfCtn"></div>
Initialize WriteFree, passing in the container:
const wf = WriteFree(document.getElementById('wfCtn'));
Presumably, you're going to want to do something with what your users write. WriteFree offers a couple methods to help with that.
As of now, there are two methods you can use to manipulate the contents of the WriteFree editor:
const wfContents = wf.html(); wf.load(wfContents);
The WriteFree.html()
method will pull the current contents of the WriteFree editor and return
it as a String of HTML elements. You can then use this String as you
wish. If you would like to reload a returned String, simply use the
WriteFree.load()
method,
passing in the String you previously obtained from the
WriteFree.html()
method.
There are a number of options that can be set on initialization. A few of these are set by default but can easily be overridden.
Options for a WriteFree instance are defined in a JavaScript Object passed in as the second parameter to the initialization function like so:
const wf = WriteFree(ctn, { optionsObject })Most of the options available are dedicated to styling the editor and its contents. The Edit Toolbar and Insert Toolbar are statically styled and can't be customized. However, the contents of the editor can be easily styled by either passing in the appropriate style Object or class.
const defaultOptions = { divOrPar: 'p', sectionClass: '', sectionStyle: { 'font-size': '1.25rem', 'max-width': '35rem', 'margin-left': 'auto', 'margin-right': 'auto', }, containerClass: '', containerStyle: { 'min-height': '2em', 'max-width': '100%', margin: '1em auto', padding: '0em 1.5rem', 'font-size': '1.25rem', 'font-family': "'Crimson Text', serif", outline: 'none', color: '#333', }, largeHeadingClass: '', largeHeadingStyle: { 'font-size': ''2rem', 'max-width': '35rem', 'margin-left': 'auto', 'margin-right': 'auto', }, smallHeadingClass: '', smallHeadingStyle: { 'font-size': '1.5rem', 'max-width': '35rem', 'margin-left': 'auto', 'margin-right': 'auto', }, imgClass: '', imgStyle: { 'margin-left': 'auto', 'margin-right': 'auto', 'max-width': '100%', }, emptyPlaceholder: 'Try writing here...', };