Skip to content

Improve references by taking sections/slices into account #175

@YakovL

Description

@YakovL

Currently, the getReferringTiddlers method of store (1) (which is used to provide references (2)) uses links provided by Tiddler.prototype.changed (3) (through TiddlyWiki.prototype.reverseLookup (4)). The changed method recognizes wikiwords, bracketed links etc via the config.textPrimitives.tiddlerAnyLinkRegExp and config.textPrimitives.tiddlerForcedLinkRegExp (5) RegExps. The latter don't distinguish [[some tiddler##section]] link-like expressions which can be used in tiddler and other macros. This causes the situation when some tiddler's references don't show the tiddler where the transclusion is used (if there's a tiddler named some tiddler##section then its references list shows the macro-containing tiddler).

So, to fix this, either changed method or getReferringTiddlers method sholud be changed. It seems reasonable to change changed method by adding a helper inside it:

var getTiddlerName = function(linkText) {
    var pos = linkText.indexOf(config.textPrimitives.sectionSeparator);
    if(pos == -1)
        pos = linkText.indexOf(config.textPrimitives.sliceSeparator);
    if(pos != -1)
        return linkText.substr(0,pos);
    return linkText;
}

and use it each time before this.links.pushUnique (like this: this.links.pushUnique(getTiddlerName(...))). This way, tiddler.links will always contain only tiddler names, not sections/slices and the references lists (as well as missing or orphans lists) will be correct.

[1] https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/TiddlyWiki.js#L511
[2] https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/Commands.js#L75
[3] https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/Tiddler.js#L126
[4] https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/TiddlyWiki.js#L520
[5] https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/Config.js#L192

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions