mediawiki-extensions-Visual.../modules/ve
Catrope 452c759914 Preserve whitespace between elements
This commit fully utilizes all four positions in the internal.whitespace
array. Outer whitespace is now preserved as well, and is duplicated
either in the adjacent sibling (one node's outerPost is the next
sibling's outerPre) or in the parent (a branch node's innerPre is its
first child's outerPre, and its innerPost is its last child's
outerPost). Before restoring saved whitespace, we check that these two
agree with each other, and if they disagree we assume the user has been
moving stuff around and don't restore any whitespace in that spot. The
whitespace at the very beginning and the very end of the document (i.e.
the first node's outerPre and the last node's outerPost) isn't
duplicated anywhere, nor is inner whitespace in content nodes.

The basic outline of the implementation is:
* When we encounter whitespace, strip it and store it in the previous
  node's outerPost. Also store it in nextWhitespace so we can put it in
  the next node's outerPre once we encounter that node.
* When we encounter whitespace in wrapped bare text, we don't know in
  advance if it's gonna be succeeded by more non-whitespace (in which
  case it needs to be output verbatim), or not (in which case it's
  leading whitespace and needs to be stripped and stored). The fact that
  annotations are nodes in HTML makes this trickier. So we write the
  whitespace to the temporary linmod and store it in wrappedWhitespace,
  then if it turns out to be trailing whitespace we take it back out of
  the data array and record it the usual way.
* Because text nodes can contain any combination of leading whitespace
  actual text and trailing whitespace, and because we may or may not
  already have opened a wrapping paragraph, there are a lot of different
  combinations to handle. We handle all of them but the resulting code
  is pretty dense and verbose.

More low-level list of changes:

In getDataFromDom():
* Added helper function addWhitespace() for storing whitespace for an
  element
* Added helper function processNextWhitespace() for processing any
  whitespace passed on from the previous node via the nextWhitespace var
* Rename paragraph to wrappingParagraph. Make wrapping default to
  alreadyWrapped so we can simplify wrapping||alreadyWrapped and
  !wrapping&&!alreadyWrapped. Add wrappingIsOurs to track whether the
  wrapping originated in this recursion level (needed for deciding when
  to close the wrapper).
* Add prevElement to track the previous element so we can propagate
  whitespace to it, and nextWhitespace so we can propagate whitespace to
  the next element.
* Remove previous newline stripping hacks
* Integrate the logic for wrapping bare content with the outer
  whitespace preservation code
* Remove wrapperElement, no longer needed because we have a dedicated
  variable for the wrapping paragraph now and what was previously inner
  whitespace preservation for wrapper paragraphs is now covered by the
  outer whitespace preservation code.

In getDomFromData():
* Reinsert whitespace where appropriate
** outerPre is inserted when opening the element
** This covers outerPost as well except for the last child's outerPost,
   which is handled as the parent's innerPost when closing the parent.
** innerPre and innerPost are inserted when closing the element. Care is
   taken not to insert these if they're duplicates of something else.
* Propagate each node's outerPost to the next node (either the next
  sibling or the parent) using parentDomElement.lastOuterPost. We can't
  get this using .lastChild because we will have destroyed that child's
  .veInternal by then, and we can't tell whether a node will be its
  parent's last child when we process it (all other processing,
  including first child handling is done when processing the node itself,
  but this cannot be).
* Special handling is needed for the last node's outerPost, which ends
  up in the container's .lastOuterPost property.

Tests:
* Allow .html to be null in data<->DOM converter tests. This indicates
  that the test is a one-way data->DOM test, not a DOM->data->DOM
  round-trip test. The data will be converted to HTML and checked
  against .normalizedHtml
* Update existing tests as needed
* Add tests for outer whitespace preservation and storage
* Add test for squashing of whitespace in case of disagreement (this
  requires .html=null)

Change-Id: I4db4fe372a421182e80a2535657af7784ff15f95
2012-08-23 19:08:00 -07:00
..
ce Merge "Bug 37904 - Show info in title of link tags" 2012-08-23 22:49:46 +00:00
dm Preserve whitespace between elements 2012-08-23 19:08:00 -07:00
init Merge "Bug 37821 - Add support for oldid" 2012-08-23 21:18:37 +00:00
test Preserve whitespace between elements 2012-08-23 19:08:00 -07:00
ui Merge "Set inspector container height and width to 0 on close." 2012-08-23 19:04:33 +00:00
ve.BranchNode.js Refactor ve.js utilities and improve documentation 2012-08-12 20:32:45 +02:00
ve.debug.js Fixing ve.log and ve.dir for IE 2012-08-22 11:04:10 -07:00
ve.Document.js This should never happen, but if it does, lets make sure we know 2012-08-08 15:17:45 -07:00
ve.EventEmitter.js Refactor ve.js utilities and improve documentation 2012-08-12 20:32:45 +02:00
ve.Factory.js Rename fringeWhitespace to internal 2012-08-16 15:14:01 -07:00
ve.js Bug 37904 - Show info in title of link tags 2012-08-23 15:21:20 -07:00
ve.LeafNode.js Puttin' em white-spacers where they aught'a be 2012-08-06 18:52:19 -07:00
ve.Node.js Make use of new jshint options 2012-08-10 02:50:30 +02:00
ve.Position.js Puttin' em white-spacers where they aught'a be 2012-08-06 18:52:19 -07:00
ve.Range.js Added basic ve.dm.SurfaceFragment class 2012-08-09 16:18:13 -07:00
ve.Surface.js Floating toolbar fixes 2012-08-20 15:43:47 -07:00