ui refactoring

ui will now correctly update with current inline and block formattings
api was refactored to provide format function
We should (almost never) use the global ```document``` reference. We should use the ```ownerDocument``` reference from a node at hand.