Source mode conversion is done through the visual mode converter, but they have differences, such as whitespace preservation, that lead to issues such as T203114.
Currently:
- In ve.init.Target.static.parseDocument, we have a special case for source mode, where the source text is split by line, and converted into an HTML document, with a <p> for each line in the source. This is then fed to the converter which generates linear model.
- Creating an HTML document is probably unnecessary for source mode, we could go straight from source text to linear data (as we do in ve.dm.SourceSurfaceFragment.prototype.insertContent)
- In ve.dm.Surface.prototype.getDom we bypass the converter completely, and use ve.dm.ElementLinearData.prototype.getSourceText to convert the document back to source text
Proposal:
- Create a new "source converter" utility that converts directly from source text to linear data, and use it to replace all of the methods listed above.
- It may need an "inline" mode, so that "a\nb" is converted to 'a',{type:/p},{type:p},'b' instead of {type:p},'a',{type:/p},{type:p},'b',{type:/p}. The former would be used by insertContent and the latter would be used when creating a new document.
This would also be a performance increase for converting source text to linear as we would remove the HTML DOM step.