mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-12-12 03:38:05 +00:00
Fix/backlink binary (#8098)
* fix: prevent check binary tiddler for backlink * refactor: test for backlink
This commit is contained in:
@@ -70,6 +70,9 @@ BackSubIndexer.prototype.rebuild = function() {
|
|||||||
* Get things that is being referenced in the text, e.g. tiddler names in the link syntax.
|
* Get things that is being referenced in the text, e.g. tiddler names in the link syntax.
|
||||||
*/
|
*/
|
||||||
BackSubIndexer.prototype._getTarget = function(tiddler) {
|
BackSubIndexer.prototype._getTarget = function(tiddler) {
|
||||||
|
if(this.wiki.isBinaryTiddler(tiddler.fields.text)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
var parser = this.wiki.parseText(tiddler.fields.type, tiddler.fields.text, {});
|
var parser = this.wiki.parseText(tiddler.fields.type, tiddler.fields.text, {});
|
||||||
if(parser) {
|
if(parser) {
|
||||||
return this.wiki[this.extractor](parser.tree);
|
return this.wiki[this.extractor](parser.tree);
|
||||||
|
|||||||
@@ -12,6 +12,24 @@ Tests the backlinks mechanism.
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe('Backlinks tests', function() {
|
describe('Backlinks tests', function() {
|
||||||
|
function setupWiki(wikiOptions) {
|
||||||
|
wikiOptions = wikiOptions || {};
|
||||||
|
// Create a wiki
|
||||||
|
var wiki = new $tw.Wiki(wikiOptions);
|
||||||
|
wiki.addIndexersToWiki();
|
||||||
|
|
||||||
|
wiki.addTiddler({
|
||||||
|
title: 'TestIncoming',
|
||||||
|
text: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
wiki.addTiddler({
|
||||||
|
title: 'TestOutgoing',
|
||||||
|
text: 'A link to [[TestIncoming]]',
|
||||||
|
});
|
||||||
|
return wiki;
|
||||||
|
}
|
||||||
|
|
||||||
describe('a tiddler with no links to it', function() {
|
describe('a tiddler with no links to it', function() {
|
||||||
var wiki = new $tw.Wiki();
|
var wiki = new $tw.Wiki();
|
||||||
|
|
||||||
@@ -25,15 +43,7 @@ describe('Backlinks tests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('A tiddler added to the wiki with a link to it', function() {
|
describe('A tiddler added to the wiki with a link to it', function() {
|
||||||
var wiki = new $tw.Wiki();
|
var wiki = setupWiki();
|
||||||
|
|
||||||
wiki.addTiddler({
|
|
||||||
title: 'TestIncoming',
|
|
||||||
text: ''});
|
|
||||||
|
|
||||||
wiki.addTiddler({
|
|
||||||
title: 'TestOutgoing',
|
|
||||||
text: 'A link to [[TestIncoming]]'});
|
|
||||||
|
|
||||||
it('should have a backlink', function() {
|
it('should have a backlink', function() {
|
||||||
expect(wiki.filterTiddlers('TestIncoming +[backlinks[]]').join(',')).toBe('TestOutgoing');
|
expect(wiki.filterTiddlers('TestIncoming +[backlinks[]]').join(',')).toBe('TestOutgoing');
|
||||||
@@ -42,15 +52,7 @@ describe('Backlinks tests', function() {
|
|||||||
|
|
||||||
describe('A tiddler that has a link added to it later', function() {
|
describe('A tiddler that has a link added to it later', function() {
|
||||||
it('should have an additional backlink', function() {
|
it('should have an additional backlink', function() {
|
||||||
var wiki = new $tw.Wiki();
|
var wiki = setupWiki();
|
||||||
|
|
||||||
wiki.addTiddler({
|
|
||||||
title: 'TestIncoming',
|
|
||||||
text: ''});
|
|
||||||
|
|
||||||
wiki.addTiddler({
|
|
||||||
title: 'TestOutgoing',
|
|
||||||
text: 'A link to [[TestIncoming]]'});
|
|
||||||
|
|
||||||
wiki.addTiddler({
|
wiki.addTiddler({
|
||||||
title: 'TestOutgoing2',
|
title: 'TestOutgoing2',
|
||||||
@@ -67,15 +69,7 @@ describe('Backlinks tests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('A tiddler that has a link remove from it later', function() {
|
describe('A tiddler that has a link remove from it later', function() {
|
||||||
var wiki = new $tw.Wiki();
|
var wiki = setupWiki();
|
||||||
|
|
||||||
wiki.addTiddler({
|
|
||||||
title: 'TestIncoming',
|
|
||||||
text: ''});
|
|
||||||
|
|
||||||
wiki.addTiddler({
|
|
||||||
title: 'TestOutgoing',
|
|
||||||
text: 'A link to [[TestIncoming]]'});
|
|
||||||
|
|
||||||
it('should have one fewer backlink', function() {
|
it('should have one fewer backlink', function() {
|
||||||
expect(wiki.filterTiddlers('TestIncoming +[backlinks[]]').join(',')).toBe('TestOutgoing');
|
expect(wiki.filterTiddlers('TestIncoming +[backlinks[]]').join(',')).toBe('TestOutgoing');
|
||||||
@@ -89,15 +83,7 @@ describe('Backlinks tests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('A tiddler linking to another that gets renamed', function() {
|
describe('A tiddler linking to another that gets renamed', function() {
|
||||||
var wiki = new $tw.Wiki();
|
var wiki = setupWiki();
|
||||||
|
|
||||||
wiki.addTiddler({
|
|
||||||
title: 'TestIncoming',
|
|
||||||
text: ''});
|
|
||||||
|
|
||||||
wiki.addTiddler({
|
|
||||||
title: 'TestOutgoing',
|
|
||||||
text: 'A link to [[TestIncoming]]'});
|
|
||||||
|
|
||||||
it('should have its name changed in the backlinks', function() {
|
it('should have its name changed in the backlinks', function() {
|
||||||
expect(wiki.filterTiddlers('TestIncoming +[backlinks[]]').join(',')).toBe('TestOutgoing');
|
expect(wiki.filterTiddlers('TestIncoming +[backlinks[]]').join(',')).toBe('TestOutgoing');
|
||||||
@@ -109,15 +95,7 @@ describe('Backlinks tests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('A tiddler linking to another that gets deleted', function() {
|
describe('A tiddler linking to another that gets deleted', function() {
|
||||||
var wiki = new $tw.Wiki();
|
var wiki = setupWiki();
|
||||||
|
|
||||||
wiki.addTiddler({
|
|
||||||
title: 'TestIncoming',
|
|
||||||
text: ''});
|
|
||||||
|
|
||||||
wiki.addTiddler({
|
|
||||||
title: 'TestOutgoing',
|
|
||||||
text: 'A link to [[TestIncoming]]'});
|
|
||||||
|
|
||||||
it('should be removed from backlinks', function() {
|
it('should be removed from backlinks', function() {
|
||||||
expect(wiki.filterTiddlers('TestIncoming +[backlinks[]]').join(',')).toBe('TestOutgoing');
|
expect(wiki.filterTiddlers('TestIncoming +[backlinks[]]').join(',')).toBe('TestOutgoing');
|
||||||
@@ -127,6 +105,41 @@ describe('Backlinks tests', function() {
|
|||||||
expect(wiki.filterTiddlers('TestIncoming +[backlinks[]]').join(',')).toBe('');
|
expect(wiki.filterTiddlers('TestIncoming +[backlinks[]]').join(',')).toBe('');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Binary tiddlers should not be parsed', function() {
|
||||||
|
var wiki = setupWiki();
|
||||||
|
|
||||||
|
wiki.addTiddler({
|
||||||
|
title: 'TestDoc.doc',
|
||||||
|
text: 'A link to [[TestOutgoing]]',
|
||||||
|
type: 'application/msword'
|
||||||
|
});
|
||||||
|
|
||||||
|
wiki.addTiddler({
|
||||||
|
title: 'TestExcel.xls',
|
||||||
|
text: 'A link to [[TestOutgoing]]',
|
||||||
|
type: 'application/excel'
|
||||||
|
});
|
||||||
|
|
||||||
|
wiki.addTiddler({
|
||||||
|
title: 'TestOutgoing',
|
||||||
|
text: 'Some links to [[TestDoc.doc]] and [[TestExcel.xls]].'
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore office files', function() {
|
||||||
|
expect(wiki.getIndexer("BackIndexer").subIndexers.link._getTarget(wiki.getTiddler('TestExcel.xls'))).toEqual([]);
|
||||||
|
|
||||||
|
expect(wiki.filterTiddlers('[all[]] +[backlinks[]]').join(',')).toBe('TestOutgoing');
|
||||||
|
|
||||||
|
// make it tw5 tiddler
|
||||||
|
wiki.addTiddler({
|
||||||
|
title: 'TestExcel.xls',
|
||||||
|
text: 'A link to [[TestOutgoing]]'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wiki.filterTiddlers('[all[]] +[backlinks[]]').join(',')).toBe('TestOutgoing,TestExcel.xls');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user