Skip to content

Commit 09dd8a6

Browse files
committed
v6.3.2
Fixed reference parsing bugs
1 parent 943c53c commit 09dd8a6

File tree

4 files changed

+34
-20
lines changed

4 files changed

+34
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "wikijs",
33
"description": "Mediawiki interface for Node and Web",
44
"author": "Richard van der Dys",
5-
"version": "6.3.1",
5+
"version": "6.3.2",
66
"keywords": [
77
"wiki",
88
"wikipedia",

src/page.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,17 @@ export default function wikiPage(rawPageInfo, apiOptions) {
241241
return null;
242242
}
243243

244+
function findNodes(node, predicate, nodes) {
245+
if (predicate(node)) {
246+
nodes.push(node);
247+
}
248+
if (node.content.children) {
249+
for (let child of node.content.children) {
250+
findNodes(child, predicate, nodes);
251+
}
252+
}
253+
}
254+
244255
/**
245256
* References from page
246257
* @example
@@ -257,14 +268,23 @@ export default function wikiPage(rawPageInfo, apiOptions) {
257268
})
258269
.then(ast => {
259270
const links = [];
260-
const refs = findNode(
271+
const refs = [];
272+
// There can be mulitple reference sections
273+
findNodes(
261274
ast,
262-
node => isTag(node) && hasClass(node, 'references')
275+
node =>
276+
isTag(node) && hasName(node, 'ol') && hasClass(node, 'references'),
277+
refs
263278
);
264-
if (refs) {
265-
for (let ref of refs.content.children[0].content.children) {
279+
for (let ref of refs) {
280+
const items = ref.content.children.filter(
281+
el => isTag(el) && hasName(el, 'li') && el.content.children
282+
);
283+
for (let item of items) {
284+
// The reference was moved under a span under li
285+
const span = item.content.children[2];
266286
const cite = findNode(
267-
ref,
287+
span,
268288
node => isTag(node) && hasName(node, 'cite')
269289
);
270290
if (cite) {

test/real.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('Live tests', () => {
2424
this.timeout(timeoutTime);
2525
setTimeout(() => {
2626
done();
27-
}, 1000);
27+
}, 100);
2828
});
2929

3030
it.skip('should handle error response', function(done) {
@@ -396,23 +396,18 @@ describe('Live tests', () => {
396396
});
397397
});
398398

399-
// Not parsing...
400-
it.skip('should return references in correct order', function() {
399+
it('should return references in correct order', function() {
401400
this.timeout(timeoutTime);
402401
return wiki()
403402
.page('Elon Musk')
404403
.then(page => page.references())
405404
.then(refs => {
406405
refs[0].should.equal(
407-
'https://www.forbes.com/sites/trulia/2013/11/01/billionaire-tesla-ceo-elon-musk-buys-home/'
406+
'https://www.independent.co.uk/life-style/elon-musk-son-grimes-childcare-interview-a9638321.html'
408407
);
409-
refs[1].should.equal(
410-
'https://web.archive.org/web/20150207033543/http://www.bloomberg.com/news/videos/b/6e27fcba-309d-494e-b87d-c73fb8bb1750'
408+
refs[3].should.equal(
409+
'https://www.fastcompany.com/1367866/tesla-lawsuit-drama-ends-five-company-founders-emerge'
411410
);
412-
refs[2].should.equal(
413-
'https://www.bloomberg.com/news/videos/b/6e27fcba-309d-494e-b87d-c73fb8bb1750'
414-
);
415-
refs[3].should.equal('https://www.forbes.com/profile/elon-musk/');
416411
});
417412
});
418413

@@ -437,8 +432,7 @@ describe('Live tests', () => {
437432
});
438433
});
439434

440-
// TODO: new html parsing is NOT working
441-
it.skip('should parse external references', function() {
435+
it('should parse external references', function() {
442436
this.timeout(timeoutTime);
443437
return wiki()
444438
.page('Batman')
@@ -447,7 +441,7 @@ describe('Live tests', () => {
447441
refs.should.containEql(
448442
'http://www.behindthevoiceactors.com/characters/Batman/Batman/'
449443
);
450-
refs.length.should.equal(140);
444+
refs.length.should.equal(143);
451445
});
452446
});
453447

test/spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('Page Methods', () => {
104104
this.timeout(timeoutTime);
105105
setTimeout(() => {
106106
done();
107-
}, 1000);
107+
}, 100);
108108
});
109109

110110
before(done => {

0 commit comments

Comments
 (0)