guardian/scribe — pull request #30 by OliverJAsh (2014-02-03 12:10:52+00:00)
Title: Add insertHTML command, which will ensure P mode when executed

Previously, if the `insertHTML` command was called with HTML such as `

1

2`, there was no guarantee that the `2` (not wrapped in an element) would be inserted into a P element, thus breaking P mode. [This behaviour is inconsistent between browsers.](https://github.com/guardian/scribe/compare/guardian:caf4802...guardian:f2493f0#diff-04c6e90faac2675aa89e2176d2eec7d8R17).

In spite of this, I presume that it should not be the browser’s responsibility to wrap empty text nodes in a P element. After all, the browser doesn't care about P mode (or rich text editors for that matter). To solve this I define a custom `insertHTML` command which, when executed, will wrap any child element that is also an inline element, before passing the new value along to the default command.

* Prior to this wrapping, we probably also want to intercept content `
` and replace it with Ps. Otherwise they end up being wrapped too, i.e. `1
2` => `

1

2

`.
* Should this logic be in the `insertHTML` command, or should it be a formatter?

Thoughts?