A general idea
This diagram shows how a new immerse directive will work together with Columnizer and Tweaker.
Editor content must be processed before inserted into Columnizer. There are 2 kinds of processing that should take place in Cleaner:
This means removing the garbage from the user generated HTML, like empty P tags, stripping trailing whitespace, wrapping text elements with P tag etc.
Cleaner must be also aware of some column layout specific logic and transform elements accordingly. For instance, removing HR.column-break tags and adding tags to the previous element. Also, IMG elements must be converted into DIVs with backgrounds.
Not sure if everything should be done in Cleaner, or maybe 1. part should be the responsibility of Editor.
Columnizer takes the cleaned HTML as an input to generate a HTML that is shown in immerse page (preview). The element's heights measured by Measurer in the process need to be saved to DB.
There are several possibilities about what to save to DB and what to generate:
.. and later always clean HTML and generate layout. This is how it is done now.
In this case, we avoid cleaning HTML every time, but still need to generate layout every time.
The idea is that generated layout HTML can be also used for mobile devices that don't show columns. The problem is that generated layout contains also duplicated content elements that needs to be hidden. Additional layout metadata can be saved together with its HTML (num of pages etc.) or extracted from DOM on the fly.
This way we would save a layout (meta)data in a lightweight data structure that is basically a nested array consisting of pages -> columns -> content elements. Every content element has a height, marginBottom and ID that corresponds to the index of node in cleaned editor HTML. Renderer takes these two as input to generate HTML, which is a relatively cheap task.