Formatter: Fix parsing for [[wiki: links]]

This commit is contained in:
Guangcong Luo 2017-11-28 07:59:51 -06:00
parent d0f66895c3
commit 3c5b4ca0fb
2 changed files with 5 additions and 4 deletions

View File

@ -277,11 +277,12 @@ class TextFormatter {
term += `<small> &lt;${shortUri}&gt;</small>`;
}
if (colonPos > 0) {
switch (this.slice(start + 2, colonPos)) {
const key = this.slice(start + 2, colonPos);
switch (key) {
case 'w':
case 'wiki':
term = term.slice(term.charAt(5) === ' ' ? 6 : 5);
uri = `http://en.wikipedia.org/w/index.php?title=Special:Search&search=${this.toUriComponent(term)}`;
term = term.slice(term.charAt(key.length + 1) === ' ' ? key.length + 2 : key.length + 1);
uri = `//en.wikipedia.org/w/index.php?title=Special:Search&search=${this.toUriComponent(term)}`;
term = `wiki: ${term}`;
break;
}

View File

@ -62,7 +62,7 @@ describe('Chat', function () {
);
assert.strictEqual(
Chat.formatText(`[[wiki: Pokemon]]`, true),
`<a href="http://en.wikipedia.org/w/index.php?title=Special:Search&search=%20Pokemon" target="_blank" rel="noopener">wiki: Pokemon</a>`
`<a href="//en.wikipedia.org/w/index.php?title=Special:Search&search=Pokemon" target="_blank" rel="noopener">wiki: Pokemon</a>`
);
assert.strictEqual(
Chat.formatText(`:)`, true),