Arlolra has uploaded a new change for review.
https://gerrit.wikimedia.org/r/264025
Change subject: Flatten ext/
......................................................................
Flatten ext/
Change-Id: I083dc0d7c5ab37c8f0f5c051e82e4705c891812d
---
M lib/config/ParsoidConfig.js
R lib/ext/Cite.js
R lib/ext/LST.js
R lib/ext/Translate.js
D lib/ext/cite/processRefs.js
5 files changed, 107 insertions(+), 118 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/25/264025/1
diff --git a/lib/config/ParsoidConfig.js b/lib/config/ParsoidConfig.js
index 1d9d667..2ab8c80 100644
--- a/lib/config/ParsoidConfig.js
+++ b/lib/config/ParsoidConfig.js
@@ -604,9 +604,9 @@
};
ParsoidConfig.prototype.defaultNativeExtensions = [
- require('../ext/cite/Cite.js').Cite,
- require('../ext/lst/LST.js'),
- require('../ext/translate/Translate.js'),
+ require('../ext/Cite.js').Cite,
+ require('../ext/LST.js'),
+ require('../ext/Translate.js'),
];
diff --git a/lib/ext/cite/Cite.js b/lib/ext/Cite.js
similarity index 79%
rename from lib/ext/cite/Cite.js
rename to lib/ext/Cite.js
index f2f61e8..2ae98a4 100644
--- a/lib/ext/cite/Cite.js
+++ b/lib/ext/Cite.js
@@ -3,15 +3,13 @@
* natively in Parsoid.
* ---------------------------------------------------------------------- */
'use strict';
-require('../../../core-upgrade.js');
+require('../../core-upgrade.js');
var entities = require('entities');
-var Util = require('../../utils/Util.js').Util;
-var DU = require('../../utils/DOMUtils.js').DOMUtils;
-var Promise = require('../../utils/promise.js');
-var defines = require('../../wt2html/parser.defines.js');
-
-var _processRefs = require('./processRefs.js')._processRefs;
+var Util = require('../utils/Util.js').Util;
+var DU = require('../utils/DOMUtils.js').DOMUtils;
+var Promise = require('../utils/promise.js');
+var defines = require('../wt2html/parser.defines.js');
// define some constructor shortcuts
var KV = defines.KV;
@@ -524,6 +522,102 @@
},
};
+/* --------------------------------------------
+ * This handles wikitext like this:
+ *
+ * <references> <ref>foo</ref> </references>
+ * <references> <ref>bar</ref> </references>
+ * -------------------------------------------- */
+var _processRefs, _processRefsInReferences;
+
+_processRefsInReferences = function(cite, refsData, node, referencesId,
+
referencesGroup, nestedRefsHTML) {
+ var child = node.firstChild;
+ while (child !== null) {
+ var nextChild = child.nextSibling;
+ if (DU.isElt(child)) {
+ var typeOf = child.getAttribute('typeof');
+ if
((/(?:^|\s)mw:Extension\/ref\/Marker(?=$|\s)/).test(typeOf)) {
+ cite.references.extractRefFromNode(child,
refsData,
+ _processRefs.bind(null, cite, refsData),
+ referencesId, referencesGroup,
nestedRefsHTML);
+ } else if (child.childNodes.length > 0) {
+ _processRefsInReferences(cite, refsData,
+ child, referencesId, referencesGroup,
nestedRefsHTML);
+ }
+ }
+
+ child = nextChild;
+ }
+};
+
+_processRefs = function(cite, refsData, node) {
+ var child = node.firstChild;
+ while (child !== null) {
+ var nextChild = child.nextSibling;
+ if (DU.isElt(child)) {
+ var typeOf = child.getAttribute('typeof');
+ if
((/(?:^|\s)mw:Extension\/ref\/Marker(?=$|\s)/).test(typeOf)) {
+ cite.references.extractRefFromNode(child,
refsData,
+ _processRefs.bind(null, cite,
refsData));
+ } else if
((/(?:^|\s)mw:Extension\/references(?=$|\s)/).test(typeOf)) {
+ var referencesId = child.getAttribute("about");
+ var referencesGroup =
DU.getDataParsoid(child).group;
+ var nestedRefsHTML = ["\n"];
+ _processRefsInReferences(cite, refsData,
+ child, referencesId, referencesGroup,
nestedRefsHTML);
+ cite.references.insertReferencesIntoDOM(child,
refsData, nestedRefsHTML);
+ } else {
+ // inline image -- look inside the data-mw
attribute
+ if (DU.isInlineImage(child)) {
+ /*
-----------------------------------------------------------------
+ * SSS FIXME: This works but feels very
special-cased in 2 ways:
+ *
+ * 1. special cased to images vs. any
node that might have
+ * serialized HTML embedded in
data-mw
+ * 2. special cased to global cite
handling -- the general scenario
+ * is DOM post-processors that do
different things on the
+ * top-level vs not.
+ * - Cite needs to process these
fragments in the context of the
+ * top-level page, and has to be
done in order of how the nodes
+ * are encountered.
+ * - DOM cleanup can be done on
embedded fragments without
+ * any page-level context and in
any order.
+ * - So, some variability here.
+ *
+ * We should be running dom.cleanup.js
passes on embedded html
+ * in data-mw and other attributes.
Since correctness doesn't
+ * depend on that cleanup, I am not
adding more special-case
+ * code in dom.cleanup.js.
+ *
+ * Doing this more generically will
require creating a DOMProcessor
+ * class and adding state to it.
+ *
----------------------------------------------------------------- */
+ var dmw = DU.getDataMw(child);
+ var caption = dmw.caption;
+ if (caption) {
+ // Extract the caption HTML,
build the DOM, process refs,
+ // save data attribs, serialize
to HTML, update the caption HTML.
+ var captionDOM =
DU.parseHTML(caption);
+ _processRefs(cite, refsData,
captionDOM.body);
+
DU.saveDataAttribsForDOM(captionDOM.body);
+ // FIXME: We do this in a lot
of places with embedded HTML,
+ // but, should we be running
the XML-serializer on it?
+ // Once again, this is a
generic cleanup to be done unrelated
+ // to this patch.
+ dmw.caption =
captionDOM.body.innerHTML;
+ }
+ }
+ if (child.childNodes.length > 0) {
+ _processRefs(cite, refsData, child);
+ }
+ }
+ }
+
+ child = nextChild;
+ }
+};
+
/**
* Native Parsoid implementation of the Cite extension
* that ties together <ref> and <references>
diff --git a/lib/ext/lst/LST.js b/lib/ext/LST.js
similarity index 86%
rename from lib/ext/lst/LST.js
rename to lib/ext/LST.js
index eb3e78e..282daca 100644
--- a/lib/ext/lst/LST.js
+++ b/lib/ext/LST.js
@@ -1,8 +1,8 @@
'use strict';
-require('../../../core-upgrade.js');
+require('../../core-upgrade.js');
-var DU = require('../../utils/DOMUtils.js').DOMUtils;
-var Promise = require('../../utils/promise.js');
+var DU = require('../utils/DOMUtils.js').DOMUtils;
+var Promise = require('../utils/promise.js');
// Special case for <section> until LST is implemented natively.
var serialHandler = {
diff --git a/lib/ext/translate/Translate.js b/lib/ext/Translate.js
similarity index 100%
rename from lib/ext/translate/Translate.js
rename to lib/ext/Translate.js
diff --git a/lib/ext/cite/processRefs.js b/lib/ext/cite/processRefs.js
deleted file mode 100644
index 46bb509..0000000
--- a/lib/ext/cite/processRefs.js
+++ /dev/null
@@ -1,105 +0,0 @@
-'use strict';
-
-var DU = require('../../utils/DOMUtils.js').DOMUtils;
-
-
-/* --------------------------------------------
- * This handles wikitext like this:
- *
- * <references> <ref>foo</ref> </references>
- * <references> <ref>bar</ref> </references>
- * -------------------------------------------- */
-var _processRefs, _processRefsInReferences;
-
-_processRefsInReferences = function(cite, refsData, node, referencesId,
-
referencesGroup, nestedRefsHTML) {
- var child = node.firstChild;
- while (child !== null) {
- var nextChild = child.nextSibling;
- if (DU.isElt(child)) {
- var typeOf = child.getAttribute('typeof');
- if
((/(?:^|\s)mw:Extension\/ref\/Marker(?=$|\s)/).test(typeOf)) {
- cite.references.extractRefFromNode(child,
refsData,
- _processRefs.bind(null, cite, refsData),
- referencesId, referencesGroup,
nestedRefsHTML);
- } else if (child.childNodes.length > 0) {
- _processRefsInReferences(cite, refsData,
- child, referencesId, referencesGroup,
nestedRefsHTML);
- }
- }
-
- child = nextChild;
- }
-};
-
-_processRefs = function(cite, refsData, node) {
- var child = node.firstChild;
- while (child !== null) {
- var nextChild = child.nextSibling;
- if (DU.isElt(child)) {
- var typeOf = child.getAttribute('typeof');
- if
((/(?:^|\s)mw:Extension\/ref\/Marker(?=$|\s)/).test(typeOf)) {
- cite.references.extractRefFromNode(child,
refsData,
- _processRefs.bind(null, cite,
refsData));
- } else if
((/(?:^|\s)mw:Extension\/references(?=$|\s)/).test(typeOf)) {
- var referencesId = child.getAttribute("about");
- var referencesGroup =
DU.getDataParsoid(child).group;
- var nestedRefsHTML = ["\n"];
- _processRefsInReferences(cite, refsData,
- child, referencesId, referencesGroup,
nestedRefsHTML);
- cite.references.insertReferencesIntoDOM(child,
refsData, nestedRefsHTML);
- } else {
- // inline image -- look inside the data-mw
attribute
- if (DU.isInlineImage(child)) {
- /*
-----------------------------------------------------------------
- * SSS FIXME: This works but feels very
special-cased in 2 ways:
- *
- * 1. special cased to images vs. any
node that might have
- * serialized HTML embedded in
data-mw
- * 2. special cased to global cite
handling -- the general scenario
- * is DOM post-processors that do
different things on the
- * top-level vs not.
- * - Cite needs to process these
fragments in the context of the
- * top-level page, and has to be
done in order of how the nodes
- * are encountered.
- * - DOM cleanup can be done on
embedded fragments without
- * any page-level context and in
any order.
- * - So, some variability here.
- *
- * We should be running dom.cleanup.js
passes on embedded html
- * in data-mw and other attributes.
Since correctness doesn't
- * depend on that cleanup, I am not
adding more special-case
- * code in dom.cleanup.js.
- *
- * Doing this more generically will
require creating a DOMProcessor
- * class and adding state to it.
- *
----------------------------------------------------------------- */
- var dmw = DU.getDataMw(child);
- var caption = dmw.caption;
- if (caption) {
- // Extract the caption HTML,
build the DOM, process refs,
- // save data attribs, serialize
to HTML, update the caption HTML.
- var captionDOM =
DU.parseHTML(caption);
- _processRefs(cite, refsData,
captionDOM.body);
-
DU.saveDataAttribsForDOM(captionDOM.body);
- // FIXME: We do this in a lot
of places with embedded HTML,
- // but, should we be running
the XML-serializer on it?
- // Once again, this is a
generic cleanup to be done unrelated
- // to this patch.
- dmw.caption =
captionDOM.body.innerHTML;
- }
- }
- if (child.childNodes.length > 0) {
- _processRefs(cite, refsData, child);
- }
- }
- }
-
- child = nextChild;
- }
-};
-
-
-if (typeof module === "object") {
- module.exports._processRefs = _processRefs;
-}
--
To view, visit https://gerrit.wikimedia.org/r/264025
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I083dc0d7c5ab37c8f0f5c051e82e4705c891812d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits