mediawiki-extensions-Visual.../modules/ve/test/dm
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
..
nodes Kranitor #1: On-boarding 2012-07-27 14:40:00 -07:00
ve.dm.BranchNode.test.js Puttin' em white-spacers where they aught'a be 2012-08-06 18:52:19 -07:00
ve.dm.Converter.test.js Preserve whitespace between elements 2012-08-23 19:08:00 -07:00
ve.dm.Document.test.js There's no such thing as ghosts, just sneaky array references 2012-08-17 10:37:28 -07:00
ve.dm.DocumentSynchronizer.test.js There's no such thing as ghosts, just sneaky array references 2012-08-17 10:37:28 -07:00
ve.dm.example.js Preserve whitespace between elements 2012-08-23 19:08:00 -07:00
ve.dm.LeafNode.test.js Kranitor #1: On-boarding 2012-07-27 14:40:00 -07:00
ve.dm.Node.test.js After much research on error objects, native = good, custom = bad 2012-08-08 10:48:53 -07:00
ve.dm.NodeFactory.test.js After much research on error objects, native = good, custom = bad 2012-08-08 10:48:53 -07:00
ve.dm.Surface.test.js Clean up: Single quotes 2012-08-07 07:02:01 +02:00
ve.dm.SurfaceFragment.test.js Added some unit tests for ve.dm.SurfaceFragment 2012-08-17 10:48:40 -07:00
ve.dm.Transaction.test.js Make use of new jshint options 2012-08-10 02:50:30 +02:00
ve.dm.TransactionProcessor.test.js Make use of new jshint options 2012-08-10 02:50:30 +02:00