Bit scary code for `editor.js` perhaps? Could it be factored into a plugin?