Commit graph

11 commits

Author SHA1 Message Date
Arlo Breault 4310b6a243 Mark up cite errors in embedded content
It's a feature of named refs that we only know at the time of inserting
the references list whether they have content or not, and are therefore
in err.  The strategy of 4438a72 was to keep pointers to all named ref
nodes so that if an error does occur, we can mark them up.

The problem with embedded content is that, at the time when we find out
about the errors, it's been serialized and stored, and so any pointers
we might have kept around are no longer live or relevant.  We need to go
back and process all that embedded content again to find where the refs
with errors are hiding.

This patch slightly optimizes that by keeping a map of all the errors
for refs in embedded content so that only one pass is necessary, rather
than for each references list.  Also note that, in the common case, this
pass won't run since we won't have any errors in embedded content.

Bug: T266356
Change-Id: I32e7bfa796cd4382c43b3b1d17b925dc97ce9f7f
2020-11-06 18:31:26 -05:00
Subramanya Sastry f00325d6cc Introduce preprocessing in the HTML -> WT direction
* This patch introduces a preprocessing step on the edited DOM.

* Existing preprocessing code has been extracted into the
  preprocessDOM method.

  Any registered extensions preprocessors are invoked on the DOM.
  So, this assumes that the htmlPreprocess extension listener is only
  applicable to the edited DOM. If we want to expose the concept of
  selective serialization through the API, we may want to add an
  additional interface method / listener to the DOMProcessor class.

  As of this patch, this is somewhat theoretical since there are no
  such extension handlers registered on either DOM. Future patches
  can clarify this better as specific needs arise.

* The handler also calls the serializer's custom preprocessing steps.
  This step is applicable to both the original as well as edited DOM
  (since DOM Diff is impacted by the results). If a need arises,
  in the future, we may introduce a new extension DOM processor method
  that applies to both original and edited DOMs.

* Right now, only selser strips section tags and non-selser wts
  doesn't need to. So, preprocessDOM there is empty. Additional
  selser-only DOM preprocessing will show up in later patches.

* Moved a stub HTML->WT preprocessor in Cite extension to RefProcessor.

Bug: T254501
Change-Id: I0c12afb2ea82617406d72ad872ac4f33678fa5f2
2020-09-30 17:12:45 -05:00
Arlo Breault 2f09cdb732 One document to rule them all
The description in T179082 suggests that by using one document for the
entire parse, we'd probably see some performance gains from not having
to import nodes when we get to the top level pipeline and we'd avoid the
validation errors from 19a9c3c.

However, the spec seems to suggest creating a new document when parsing
an HTML fragment,
https://html.spec.whatwg.org/#html-fragment-parsing-algorithm

And, indeed, domino implements it that way,
12a5f67136/lib/htmlelts.js (L84-L96)

So, the request in T217705 may be a little misguided.

What then is this patch good for?  In T221790 the ask is that
sub-pipelines produce DocumentFragment which make for cleaner interfaces
and less confusion when migrating children.

The general outline here is that a document is created when the
environment is constructed that gives us the 1-1 correspondence.
Sub-pipelines do create their own documents for the purpose of tree
building, as in the fragment parsing algorithm, but are then immediately
imported to DocumentFragments to be used for the rest of the
post-processing passes.

Bug: T221790
Bug: T179082
Bug: T217705
Change-Id: Idf856d4e071d742ca38486c8ab402e39b3c8949f
2020-09-29 22:36:33 +00:00
C. Scott Ananian 51c211047a All extension DOM processors should extend Ext\DOMProcessor
Change-Id: Ide9700747b3ecea9da59911c6eb342569be4c9b8
2020-05-03 21:15:41 +00:00
Subramanya Sastry 0cc3ca1b98 Move DomSourceRange to Core; ParsoidExtensionApi to Ext
* At this point, DSR is a first-class Parsoid concept and
  extensions will need to use this as well. So, make it part
  of the Core/ namespace to capture high-level concepts that
  might be used outside Parsoid itself.

* Move ParsoidExtensionApi to the Ext directory since that is
  where it best belongs.

Change-Id: If824c4af9e2f8d658f1cb726cbd837222b60790d
2020-03-16 15:52:08 +00:00
Subramanya Sastry 2f9f5e25ef Pass $extApi, not $env to extension callbacks
* $env was unused in extension DOM post processors. So get rid of
  that since we are already in the process of removing $env access
  to extensions.

* html2wtPreProcessor is currently unimplemented but there is WIP
  code in Parsoid/JS that can be revived at a later point. No need
  to pass $env here as well.

* In both cases, pass $extApi so they can access any necessary
  helpers or state provided by that API object.

Bug: T242746
Change-Id: I1d1544af817d03e01a569e6aeaeed0d6c3058fc0
2020-03-02 19:21:07 +00:00
Subramanya Sastry d0a9c42c98 Cite: Remove more Parsoid internals knowledge
* Remove use of $env from ReferencesData and RefGroup by
  providing high-level helpers in ParsoidExtensionAPI.

  - Given a fragment id, provide helpers to fetch fragment DOM
    or fragment HTML
  - Fetch the URI for the current page (being parsed)

* There is still a lot of subtle knowledge Cite has about
  how data-parsoid and data-mw attributes are held off to the
  side in a bag and all the pp* and load/store manipulation
  of those attributes. It would be an interesting exercise
  to purge this implementation of those notions OR figure out
  high-level concepts that we document as being part of Parsoid
  reality that we'll forever support.

Bug: T242746
Change-Id: I29ff154f2f17123b9756dfd2f3b422f0b30222b1
2020-02-11 19:47:28 +00:00
Subramanya Sastry 5e256b48aa Start untangling Parsoid internals from extensions
* In this patch, toDOM, fromDOM, and DOM postprocessor extension
  methods all get a ParsoidExtensionAPI object. These API objects
  are constructed at the appropriate times in the wt2html and html2wt
  pipelines.

* Got rid of direct references to SerializerState from fromDOM
  methods in extensions.

* Exposed generic serialization and wikitext escaping methods
  in ParsoidExtensionAPI for extensions to leverage. The implementation
  of these methods is partial and only supports current usage
  of extensions in Parsoid's repo. This will need to be fully
  fleshed out going forward.

* Stopped exposing wt2html options in toto and provided more specific
  convenience methods.

* Reduced direct access to the Env object in a few more places.

* Cite has code to inspect embedded HTML in data attributes of a node.
  Moved this code out of Cite into ParsoidExtensionAPI which reduces
  knowledge that extensions need. Unlike the other cleanups, this one
  is more of a convenience method since this code only requires
  knowledge of a publicly published spec. But, nevertheless an useful
  cleanup since it simplifies Cite's complexity just a bit.

* More followup work is needed.
  - before/after methods should be eliminated in favour of a config flag
    that implements the inline/block layout option. Once this is done,
    extensions will no longer need direct access to the SerializerState
    internal object.
  - Env exposure should be reduced.
  - Provide access to Sanitizer via ParsoidExtensionAPI instead of
    needing extensions to directly import it.
  - It should be possible to eliminate the need for extensions to know
    about DSR / DSR-shifting and do it automatically via some high-level
    conceptual flag.
  - It might also be possible to infer source offsets directly via args
    instead of passing that explicitly.
  - Should we provide a convenience helper class with access to all the
    src/Utils/* methods?

Bug: T242746
Change-Id: I7ffb5aa52a84854a9d363a0e8f1ce650241f1c41
2020-02-06 20:55:27 -05:00
C. Scott Ananian 5d200e0bf0 Move all code from Parsoid to Wikimedia\Parsoid namespace
This matches core conventions.

Bug: T240054
Change-Id: I5feb8a6b41503accd01a740195256e9092609272
2020-02-03 21:34:49 +00:00
Pavel Astakhov 005176a355 Port Cite extension
* All wt2wt, html2wt, and all but one html2html tests pass in
  hybrid mode when entire html2wt code is run in PHP

  Set "Serializer: true" in the html2wt section of phpconfig.yaml

* The single failing html2html test is a <gallery> test which is
  presumably related to the unported <gallery> extension code, but
  not sure. Not investigating it now.

* Update Parsoid Extension API to provide access to extension source
  without exposing internals.

Change-Id: I6d6e21ad2324acfc4306b32c9055d6c088708c48
2019-06-21 16:23:42 -05:00
Arlo Breault 05cb13ddf9 Make extensions with post-processors return constructors
This allows us to finish the cleanup started in 0b3bb10 and inline
setupProcessors.

Change-Id: Ia7840091607e9a75153031b5db7600d5a0018da6
2019-04-03 18:44:21 +00:00