jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/352177 )
Change subject: Refactor the pipetrick handler to avoid using `text()`.
..
Refactor the pipetrick handler to avoid using `text()`.
Change-Id: I720cc0d75c483068090773f7d5a8a183ea6148ce
---
M lib/wt2html/pegTokenizer.pegjs
M tests/parserTests.txt
2 files changed, 30 insertions(+), 19 deletions(-)
Approvals:
jenkins-bot: Verified
Arlolra: Looks good to me, approved
diff --git a/lib/wt2html/pegTokenizer.pegjs b/lib/wt2html/pegTokenizer.pegjs
index a7317e9..5e09a0c 100644
--- a/lib/wt2html/pegTokenizer.pegjs
+++ b/lib/wt2html/pegTokenizer.pegjs
@@ -933,17 +933,11 @@
}
wikilink_content
- = lcs:( pipe startPos:("" { return endOffset(); }) lt:link_text? {
+ = ( pipe startPos:("" { return endOffset(); }) lt:link_text? {
var maybeContent = new KV('mw:maybeContent', lt, [startPos,
endOffset()]);
maybeContent.vsrc = input.substring(startPos, endOffset());
return maybeContent;
-} ) + {
-if (lcs.length === 1 && lcs[0].v === null) {
-return { content: [], pipetrick: true };
-} else {
-return { content: lcs };
-}
-}
+ } )*
// TODO: handle link prefixes as in al[[Razi]]
wikilink
@@ -953,25 +947,31 @@
// XXX: disallow pipe!
target:wikilink_preprocessor_text?
tpos:("" { return endOffset(); })
-lcontent:wikilink_content?
+lcs:wikilink_content
"]]"
{
- if (lcontent === null) {
- lcontent = { content: [] };
- }
-
- if (target === null || lcontent.pipetrick) {
-return [text()];
- }
-
- var obj = new SelfclosingTagTk('wikilink');
+ var pipeTrick = (lcs.length === 1 && lcs[0].v === null);
var textTokens = [];
+ if (target === null || pipeTrick) {
+textTokens.push("[[");
+if (target) {
+ textTokens.push(target);
+}
+lcs.forEach(function(a) {
+ // a is a mw:maybeContent attribute
+ textTokens.push("|");
+ if (a.v !== null) { textTokens.push(a.v); }
+});
+textTokens.push("]]");
+return textTokens;
+ }
+ var obj = new SelfclosingTagTk('wikilink');
var hrefKV = new KV('href', target);
hrefKV.vsrc = input.substring(startOffset() + 2, tpos);
// XXX: Point to object with path, revision and input information
// obj.source = input;
obj.attribs.push(hrefKV);
- obj.attribs = obj.attribs.concat(lcontent.content);
+ obj.attribs = obj.attribs.concat(lcs);
obj.dataAttribs = {
tsr: tsrOffsets(),
src: text(),
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index a666b34..c95f81f 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -13181,6 +13181,17 @@
!! end
!! test
+Parsoid: backwards pipe trick
+!! wikitext
+[[|'''bar''']]
+!! html/php
+[[|bar]]
+
+!! html/parsoid
+[[|bar]]
+!! end
+
+!! test
pre-save transform: trim trailing empty lines
!! options
pst
--
To view, visit https://gerrit.wikimedia.org/r/352177
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I720cc0d75c483068090773f7d5a8a183ea6148ce
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: C. Scott Ananian
Gerrit-Reviewer: Arlolra
Gerrit-Reviewer: C. Scott Ananian
Gerrit-Reviewer: jenkins-bot <>
___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits