Cloning Medium with Parchment
To provide a consistent editing experience, you need both consistent data and predictable behaviors. The DOM unfortunately lacks both of these. The solution for modern editors is to maintain their own document model to represent their contents. Parchment is that solution for Quill. It is organized in its own codebase with its own API layer. Through Parchment you can customize the content and formats Quill recognizes, or add entirely new ones.
In this guide, we will use the building blocks provided by Parchment and Quill to replicate the editor on Medium. We will start with the bare bones of Quill, without any themes, extraneous modules, or formats. At this basic level, Quill only understands plain text. But by the end of this guide, links, videos, and even tweets will be understood.
Groundwork
Let's start without even using Quill, with just a textarea and button, hooked up to a dummy event listener. We'll use jQuery for convenience throughout this guide, but neither Quill nor Parchment depends on this. We'll also add some basic styling, with the help of Google Fonts and Font Awesome . None of this has anything to do with Quill or Parchment, so we'll move through quickly.
<link href="/styles.css" rel="stylesheet"> <div id="tooltip-controls"> <button id="bold-button"><i class="fa fa-bold"></i></button> <button id="italic-button"><i class="fa fa-italic"></i></button> <button id="link-button"><i class="fa fa-link"></i></button> <button id="blockquote-button"><i class="fa fa-quote-right"></i></button> <button id="header-1-button"><i class="fa fa-header"><sub>1</sub></i></button> <button id="header-2-button"><i class="fa fa-header"><sub>2</sub></i></button> </div> <div id="sidebar-controls"> <button id="image-button"><i class="fa fa-camera"></i></button> <button id="video-button"><i class="fa fa-play"></i></button> <button id="tweet-button"><i class="fa fa-twitter"></i></button> <button id="divider-button"><i class="fa fa-minus"></i></button> </div> <textarea id="editor">Tell your story...</textarea> <script type="module" src="/index.js"></script>