Re:Pell – A simple and small rich-text editor for the web
by chrismorgan on Thursday July 13, 2017 @06:32AM
(#14760145)
And the really fun thing? Just write the HTML that it would have written directly, and the result is also under 2KB, this time ~585 bytes gzipped, and with the same functionality (though as written here `onChange` is kind of a global now). It looks like this (with line breaks added):
<div class=pell-actionbar
><button class=pell-button title=Bold onclick="document.execCommand('bold',!1)"><b>B</b></button
><button class=pell-button title=Italic onclick="document.execCommand('italic',!1)"><i>I</i></button
><button class=pell-button title=Underline onclick="document.execCommand('underline',!1)"><u>U</u></button
><button class=pell-button title=Strike-through onclick="document.execCommand('strikeThrough',!1)"><s>S</s></button
><button class=pell-button title="Heading 1" onclick="document.execCommand('formatBlock',!1,'<H1>')"><b>H<sub>1</sub></b></button
><button class=pell-button title="Heading 2" onclick="document.execCommand('formatBlock',!1,'<H2>')"><b>H<sub>2</sub></b></button
><button class=pell-button title=Paragraph onclick="document.execCommand('formatBlock',!1,'<P>')">¶</button
><button class=pell-button title=Quote onclick="document.execCommand('formatBlock',!1,'<BLOCKQUOTE>')">“ ”</button
><button class=pell-button title="Ordered List" onclick="document.execCommand('insertOrderedList',!1)">#</button
><button class=pell-button title="Unordered List" onclick="document.execCommand('insertUnorderedList',!1)">•</button
><button class=pell-button title=Code onclick="document.execCommand('formatBlock',!1,'<PRE>')"></></button
><button class=pell-button title="Horizontal Line" onclick="document.execCommand('insertHorizontalRule',!1,'<PRE>')">―</button
><button class=pell-button title=Link onclick="var s=prompt('Enter the link URL');s&&document.execCommand('createLink',!1,/^https?:\/\//.test(s)?s:'http://'+s)"></button
><button class=pell-button title=Image onclick="var s=prompt('Enter the image URL'));s&&document.execCommand('insertImage',!1,/^https?:\/\//.test(s)?s:'http://'+s)"></button
><button class=pell-button title=Undo onclick="document.execCommand('undo',!1)">↺</button
><button class=pell-button title=Redo onclick="document.execCommand('redo',!1)">↻</button
></div
><div class=pell-editor contenteditable oninput="typeof onChange=='undefined'||onChange(event.target.innerHTML)"></div>
Of course, if you decide to abandon AMD/CommonJS support, you can quickly whip 210 bytes (100 gzipped) off, but that’s a change in semantics so I can’t count that despite it getting it under 1000 bytes.