Commit graph

319 commits

Author SHA1 Message Date
jenkins-bot fa1f760deb Merge "Add MWMetaNode to clean up <meta>/<link> hack in the converter" 2013-02-22 23:26:24 +00:00
jenkins-bot 4e0ebfdba0 Merge "Support RDFa type regexes in ModelRegistry" 2013-02-22 23:26:21 +00:00
jenkins-bot fb11cc8a8c Merge "(bug 45062) Implement the new node API in the converter" 2013-02-22 23:26:18 +00:00
jenkins-bot 482c89a916 Merge "Change context.wrapping to context.inWrapper" 2013-02-22 23:26:15 +00:00
jenkins-bot 950ff37d9b Merge "Add .static.enableAboutGrouping" 2013-02-22 23:26:12 +00:00
jenkins-bot 78232847db Merge "Add .static.storeHtmlAttributes" 2013-02-22 23:26:09 +00:00
Catrope 04c72f6871 Add MWMetaNode to clean up <meta>/<link> hack in the converter
Change-Id: I4c69bff4981eef78415b43d31c3fd2ee271450ef
2013-02-22 15:21:40 -08:00
Catrope 314817925a Support RDFa type regexes in ModelRegistry
Change-Id: Id19c3a567140f9e27ba732b6e8d9e25bc7a28a4f
2013-02-22 15:21:40 -08:00
Catrope 2e36f1542b (bug 45062) Implement the new node API in the converter
This changes the node API to work with multiple elements, so we can
support about groups. Instead of passing in and returning single DOM
elements, we use arrays of DOM elements.

ve.dm.Converter:
* Pass modelRegistry into the constructor
* Remove onNodeRegister handler and its data
* Remove getDataElementFromDomElement() and
  getDataAnnotationFromDomElement(). Most logic moved into
  getDataFromDom(), some into createDataElement()
* Remove createAlien(), replaced with
  createDataElement( ve.dm.AlienNode, ... )
* Replace doAboutGrouping() (which wrapped about groups) with
  getAboutGroup() (which returns an array of the nodes in the group)
* Put in a hack so <meta>/<link> elements with an mw: property aren't
  alienated
* Remove about group wrapping behavior in favor of just outputting
  multiple nodes

ve.dm.AlienNode.js:
* For multi-element aliens, only choose inline if all elements are
  inline, not just the first one

ve.dm.example.js:
* Add html/0 stuff for meta nodes
* Fix test case to reflect new alien behavior

Change-Id: I40dcc27430f778bc00a44b91b7d824bfb2718be6
2013-02-22 15:21:40 -08:00
Catrope 5e16141750 Change context.wrapping to context.inWrapper
It's what the docs say it should be, so let's call it that :)

Change-Id: Ia10861ce77872243beb3d3a1886877824103f6c9
2013-02-22 15:21:40 -08:00
Catrope cf9e5dd953 Add .static.enableAboutGrouping
Defaults to false, nodes can opt into about grouping. Not being used
yet, will be used in the converter rewrite.

Change-Id: Ic2a529241e69fb07ac926c826ead0108193b3050
2013-02-22 15:21:40 -08:00
Catrope bbe3783d58 Add .static.storeHtmlAttributes
Defaults to true, but set to false, so we don't do redundant work for
aliens.

Change-Id: If35db3a67afd78124b4b2b46bb78ad60cbac46f5
2013-02-22 15:21:31 -08:00
jenkins-bot 26e623940a Merge "Implement SurfaceFragment.unwrapAllNodes and fix wrapAllNodes." 2013-02-22 22:36:03 +00:00
jenkins-bot 5c78ba9b6a Merge "Fix bug with replacements in translateOffset()" 2013-02-22 22:33:48 +00:00
jenkins-bot 8e0348c803 Merge "Fix ModelRegistry stupidities" 2013-02-22 22:31:03 +00:00
Ed Sanders 4f0ac479ed Implement SurfaceFragment.unwrapAllNodes and fix wrapAllNodes.
wrapAllNodes was calulating the new selection incorrectly. This has
been fixed and a test added.

unwrapAllNodes takes a depth as its argument and unwraps that many
elements from inside the selection.

Tests for wrap/unwrap apply also now check that applying a wrap
and then its inverse as an unwrap result in the document reverting
to its original state.

Change-Id: I7dcacdfb5894be59ffad69b369d7b32933a25b61
2013-02-22 13:37:42 -08:00
Catrope 8f84982e0d Fix bug with replacements in translateOffset()
In our test case, offset 12 was mapped to 16, but that should be 11.
The problem here was that the offset right before the removal was
mapped to right after the removal, but that's only valid if we're
dealing with a removal, not when we're dealing with a replacement
where we're both removing and inserting data.

Change-Id: Ibf3c1463c0de009578cd50736f19bae82669ced8
2013-02-22 13:35:33 -08:00
jenkins-bot 1ef5c07a93 Merge "(bug 45423) Create SurfaceFragment.isolate method" 2013-02-22 20:40:32 +00:00
Ed Sanders feaa422495 (bug 45423) Create SurfaceFragment.isolate method
This method will take a selection of siblings and ensure they
are the only chlidren in their first parent which can be placed anywhere
(for example the first parent of a tableCell which can be placed anywhere
is a table, and for a listItem is a list).

The method ensures no redundant empty tags are created, so if
the selection encompasses all siblings then no action is taken.

Also in this commit are two test cases run against ve.dm.example.isolationData.

Change-Id: I783bd5ecd9d43d61f9b2685985409b4d746cbe94
2013-02-22 12:38:06 -08:00
Catrope a095c0ab06 Change {Boolean} to {boolean} throughout
Change-Id: Ibbbaed3762efa6a6928ba6e4611b1f1fef91ad8f
2013-02-20 10:03:55 -08:00
Catrope b553cb9f21 Fix ModelRegistry stupidities
* Register mw: as an extension-specific type
* Include 'property' as an RDFa type attribute

Change-Id: Ia70708b76294815eb8eb8132048c33b0636380e9
2013-02-20 09:30:15 -08:00
James D. Forrester 82114467f1 Bump copyright notice year range to -2013 over -2012
199 files touched. Whee!

Change-Id: Id82ce4a32f833406db4a1cc585674f2bdb39ba0d
2013-02-19 15:37:34 -08:00
Catrope 3035c311ec Make the converter work with full HTML documents rather than fragments
The Parsoid output will also be expected to be a full HTML document. For
backwards compatibility, we allow for the Parsoid output to be a
document fragment as well. We don't send a full document back yet, also
for b/c -- we'll change this later once Parsoid has been updated in
production.

ve.dm.Converter.js:
* Make getDataFromDom() accept a document rather than a node
** Split off the recursion (which does use nodes) into its own function
** For now we just convert the <body>. In the future, we'll want to do
   things with the <head> as well
* Pass the document around so we can use it when creating elements
* Make getDomFromData() return a document rather than a <div>

ve.init.mw.Target.js:
* Store a document (this.doc) rather than a DOM node (this.dom)
* Pass around documents rather than DOM nodes
* Detect whether the Parsoid output is an HTML document or a fragment
  using a hacky regex
* When submitting to Parsoid, submit the innerHTML of the <body>

ve.init.mw.ViewPageTarget.js:
* s/dom/doc/
* Store body.innerHTML in this.originalHtml

ve.Surface.js:
* s/dom/doc/

demos/ve/index.php:
* Don't wrap HTML in <div>
* Pass HTML document rather than DOM node to ve.Surface

ve.dm.Converter.test.js:
* Construct a document from the test HTML, rather than a <div>

ve.dm.example.js:
* Wrap the HTML in the converter test cases in <body> tags to prevent
  misinterpretation (HTML fragments starting with comments, <meta>,
  <link> and whitespace are problematic)

Change-Id: I82fdad0a099febc5e658486cbf8becfcdbc85a2d
2013-02-19 10:38:39 -08:00
jenkins-bot 2b352c577c Merge "(bug 45029) Transactions for metadata modification." 2013-02-15 01:28:44 +00:00
Ed Sanders 67e9d5d1dd (bug 45029) Transactions for metadata modification.
Have created builders for insertion, removal, and single element replacement.

In adding Document.getMetadata which is nearly identical to Document.getData,
the two functions have been refactored to use a common static method
getDataSlice, with this.data/this.metadata as an argument.

Document.spliceMetadata has been added. It is essentially spliceData with
the data/metadata synchronisation issue.

Metadata cursor position is now tracked in the TransactionProcessor. Cursor
advancement has been moved to a function so the metadata cursor can be reset
every time the data cursor is moved.

There were unhit bugs in the TransactionProcessor run test section, where
the data being loaded into the test documents wasn't always being deep-copied,
and the assert was looking at getData instead of getFulldata (which wouldn't
be able to test metadata changes).

Change-Id: Ieb20ab3e7827bc7ff04148f147da6728eb1eb666
2013-02-14 17:27:27 -08:00
jenkins-bot a1bd1db241 Merge "Use .static.isMeta to communicate meta-ness" 2013-02-14 18:47:48 +00:00
Trevor Parscal 9eed973ca5 ve.dm.DocumentSlice does not extend ve.Node
Change-Id: I11d28d6eb1c7db1d6b5796ec36c8e9a6f46b7c9e
2013-02-08 14:11:11 -08:00
Catrope 28512c9488 Use .static.isMeta to communicate meta-ness
This gets rid of the meta-specific hack in ve.dm.Document

Later on, I want to use this to get rid of meta-specific hacks in the
converter too, by pushing some of that logic into the ModelFactory.

Change-Id: I1dbee1654fa32d9c7cd521ec325b2553cde219d1
2013-02-07 17:17:34 -08:00
Catrope 591f2e7396 Change the HTML attribute prefix from html/ to html/0/
This means that <p data-foo="bar"> will now be converted to a paragraph
with attributes {"html/0/data-foo":"bar"} rather than {"html/foo":"bar"}

This paves the way for multi-element node (about group) handling in the
node API: nodes representing multiple DOM elements will have html/i/attr
to represent an attribute of the i'th DOM element.

Change-Id: Iea52bdccd721942ca708c8f9f47e934524809845
2013-02-06 12:00:43 -08:00
Catrope 57ad316988 Fix bug where inline nodes didn't trigger wrapping
When encountering an inline node (i.e. content node that's not a text
node) within a branch node that's not a content branch node, the
converter should start a wrapper. But it doesn't do this, it only opens
wrappers for text nodes and annotations.

Fixed this in the converter, added a test for it, and fixed an existing
test that asserted the broken behavior.

Change-Id: I6e143e21e68b68f0d85b8772e24a2d3a5d465410
2013-02-01 16:06:17 -08:00
Catrope a97f777685 Introduce context object in getDataFromDom()
* Introduce context object as specified for
  ve.dm.Node.static.toDataElement()
* Remove wrapping variable in favor of context.wrapping
* Remove wrappingIsOurs in favor of context.canCloseWrapper
* Introduce originallyExpectingContent and use it to repopulate
  context.expectingContent after closing a wrapper
* Replace most uses of branchHasContent with context.expectingContent
** Except for two cases where we need originallyExpectingContent

These changes fix a case where a metaBlock was generated in an inline
position. Updated the tests to reflect this.

Change-Id: I6baf6053f8a3a0b7d91487f812b9235a7b2b3db1
2013-01-31 15:00:00 -08:00
Catrope 1927330352 Use AnnotationSet rather than array in getDataFromDom()
Change-Id: Ie5f1f94bd62739ccf74c027dd0ba418fe2d91fa6
2013-01-31 15:00:00 -08:00
Catrope e083afb029 Hybrid-ify MetaBlock/MetaInline
Change-Id: I7b7a2d50637e2009742b290cb1bd0f4fc0395934
2013-01-31 15:00:00 -08:00
Catrope c0690634ee Hybrid-ify AlienBlock/AlienInline
Change-Id: Ieda8383c0c04df208f4c5f2aa7380427467049b7
2013-01-31 14:59:59 -08:00
Catrope ac6c9b2418 Specify (but do not implement) the context parameter to toDataElement()
This allows the converter to provide the node handlers with context
information, which hybrid nodes (such as alien and meta) need to decide
which shape to take.

Change-Id: I36860bee560a38ee39a149109be3706e39258edc
2013-01-31 14:59:59 -08:00
Trevor Parscal 100e67c128 Fixed documentation warning
Please use backtick (it's to the left of the 1 key) around HTML elements in comments.

Change-Id: I473e88a2cb1f7fb725f21cd0e8b3f659189c15a0
2013-01-30 12:52:03 -08:00
jenkins-bot 602d01e461 Merge "Added tests and fixed inconsistencies for empty text node handling" 2013-01-29 23:16:30 +00:00
jenkins-bot 9bf5eb5b5b Merge "Added support for passing data into annotation constructors" 2013-01-29 23:15:21 +00:00
Trevor Parscal 16310f7535 Added tests and fixed inconsistencies for empty text node handling
Continues where Ibb682332a6084e357104183641a104e3ae1e253f left off, adding tests and removing inconsistencies between the behavior of the document constructor, which was adding empty text nodes to empty paragraphs, and correcting other tests which expected empty text nodes to be there as well.

Change-Id: I414d061cdd494b8023f14e944eda2910a4dab0d4
2013-01-29 15:13:17 -08:00
Trevor Parscal ea4b42b2b2 Automatically prune empty text nodes
When there's 2 entities or inline content nodes (like aliens) with text between them, removing that text should remove the node too. If you don't remove the node then CE won't think to make a slug between the two inline nodes.

Change-Id: Ibb682332a6084e357104183641a104e3ae1e253f
2013-01-28 17:09:56 -08:00
Trevor Parscal 280c85d8e7 Added support for passing data into annotation constructors
This resolves a TODO

* Added logic to support passing an argument into annotation constructor which is used as the data property (reusing the element argument)
* Updated documentation
* Simplified instantiation of annotations

Change-Id: I142b8fa3883bf70c896a2a568088d833814ef2dc
2013-01-28 11:01:52 -08:00
Catrope d73d6e9bf0 Add extension-specific types functionality to ModelRegistry
Extension-specific types are RDFa types (or type regexes) that are
registered with the ModelRegistry separately. If an element has a type
that is extension-specific, then that element can only be matched by a
rule that asserts one of its extension-specific types.

For MediaWiki, we would call
ve.dm.modelRegistry.registerExtensionSpecificType(/^mw:/ ) .
So then an element like <span typeof="mw:foobar"> would either match a
rule specifically for mw:foobar, if one exists, or no rule at all; even
the rule for <span> would not match. The consequence of this is that
elements with unrecognized mw:-prefixed RDFa types are alienated.

Change-Id: Ia8ab1fe5dffb9f813689324372a168e8e4a3e0bc
2013-01-22 18:12:35 -08:00
Catrope 99df776543 Allow matchTagNames = null in ve.dm.Converter
This won't usefully register the node with the converter right now, but
we need to allow this because the ModelFactory tests will need to have
stub nodes with tag-only matches.

Change-Id: I023cc8ff647363ab55c73dff39b17ca47e9e6681
2013-01-22 17:45:43 -08:00
Catrope aa372b6c16 Actually use this.nodeFactory and this.annotationFactory in ve.dm.Converter
Change-Id: I138a437d2e64577ad905ff70ecedf1eb7e6c8360
2013-01-22 15:55:11 -08:00
Catrope 5a5b4b577a Drop name parameter from ModelRegistry.register(), use .static.name
Change-Id: I74eeab1195455072ae48ac0655582f2bf01806d6
2013-01-22 15:55:11 -08:00
Catrope 819b3ded33 Move matching code from AnnotationFactory to ModelRegistry
ModelRegistry registers both annotations and nodes, and performs
matching on both at the same time. It also registers annotations with
the AnnotationFactory, and nodes with the NodeFactory.

Change-Id: I5e68e506a0e573cc0afe6304ccea058ffc20d1c8
2013-01-22 15:51:37 -08:00
Trevor Parscal bf5ba1ea2b Fixed documentation errors
Many of these problems were introduced in I859b5871a9d2f17d970c002067c8ff24f3513e9f

Change-Id: Ifc2dc4934f782c4ce5107e3a356e357aef754083
2013-01-22 23:38:01 +00:00
Catrope c1b6e95042 Make defaultAttributes a static property as well
Change-Id: I8ee4796a93d55db9be6e43c78f3ac7bb29a65c6f
2013-01-18 14:51:40 -08:00
Catrope 12544c9e82 Replace nodeFactory invocations with direct static access
Change-Id: I2629c5fd659bca166237cef425f7cc3aff13ba0e
2013-01-18 14:51:40 -08:00
Catrope 51f4b4be54 Convert node rules to static properties
Change-Id: If7d0159e984d9ccb4d5c31effb62bb9612260fda
2013-01-18 14:51:40 -08:00