-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve references by taking sections/slices into account #175
Comments
Anyone picking up on your well documented requests, @YakovL? |
@tobibeer |
Mhhh, I hope Eric will pick up on those issues. No idea about the traction of TW2 these days. So long as there is one who is willing and able to maintain, even further enhance, I see no obstacles to doing so... even if still a competitive product to TW5, especially with TiddlySpace being all TW2 (still!)... and TW5 not being in the Templates on TiddlySpot... as far as basic users are concerned that don't build via node.js. |
By the way, I've created a fixing plugin. Changing core requires fewer lines and can be done by either adding separate RegExps for the var orig_BRP_changed = Tiddler.prototype.changed;
// this recalcs links according to config.textPrimitives.tiddlerAnyLinkRegExp and
// config.textPrimitives.tiddlerForcedLinkRegExp , so temporarily hijack them
Tiddler.prototype.changed = function()
{
var brackettedLinkRE = config.textPrimitives.brackettedLink,
// titledBrackettedLinkRE = config.textPrimitives.titledBrackettedLink,
sectionOrSliceAddition =
"(?:(?:(?:"+config.textPrimitives.sliceSeparator+"[^\\|\\n\\]]+)|"+ //::
"(?:"+config.textPrimitives.sectionSeparator+"[^\\n\\]]+))?)", //##
tiddlerForcedLinkRegExp = config.textPrimitives.tiddlerForcedLinkRegExp,
tiddlerAnyLinkRegExp = config.textPrimitives.tiddlerAnyLinkRegExp;
// hijack REs
config.textPrimitives.brackettedLink = "\\[\\[([^\\]]+?)"+ // extra "?" is important here
sectionOrSliceAddition+
"\\]\\]";
// core definition: "\\[\\[([^\\]]+)\\]\\]";
// config.textPrimitives.titledBrackettedLink = "\\[\\[([^\\[\\]\\|]+)\\|([^\\[\\]\\|]+?)"+
// sectionOrSliceAddition+
// "\\]\\]";
// core definition: "\\[\\[([^\\[\\]\\|]+)\\|([^\\[\\]\\|]+)\\]\\]";
// recalc, as in the core:
config.textPrimitives.tiddlerForcedLinkRegExp = new RegExp("(?:" +
config.textPrimitives.titledBrackettedLink + ")|(?:" +
config.textPrimitives.brackettedLink + ")|(?:" +
config.textPrimitives.urlPattern + ")","mg");
config.textPrimitives.tiddlerAnyLinkRegExp = new RegExp("("+
config.textPrimitives.wikiLink + ")|(?:" +
config.textPrimitives.titledBrackettedLink + ")|(?:" +
config.textPrimitives.brackettedLink + ")|(?:" +
config.textPrimitives.urlPattern + ")","mg");
var result = orig_BRP_changed.apply(this,arguments);
// unhijack REs
config.textPrimitives.brackettedLink = brackettedLinkRE;
// config.textPrimitives.titledBrackettedLink = titledBrackettedLinkRE;
// recalc again
config.textPrimitives.tiddlerForcedLinkRegExp = new RegExp("(?:" +
config.textPrimitives.titledBrackettedLink + ")|(?:" +
config.textPrimitives.brackettedLink + ")|(?:" +
config.textPrimitives.urlPattern + ")","mg");
config.textPrimitives.tiddlerAnyLinkRegExp = new RegExp("("+
config.textPrimitives.wikiLink + ")|(?:" +
config.textPrimitives.titledBrackettedLink + ")|(?:" +
config.textPrimitives.brackettedLink + ")|(?:" +
config.textPrimitives.urlPattern + ")","mg");
return result; // in fact, there's no result, this is for possible future extensions
}; PS commented out stuff seems to be unnecessary in all cases. The point of this plugin is making stuff like @tobibeer , you can see some datails at [1]. Basically, I need some help with GitHub/Git and cooking process (or study them myself, which requires some extra time), but in terms of development yes, I can add some tested improvements. Not sure if I can manage the whole project (issues, stuff like TiddlySaver) though. [1] https://groups.google.com/forum/#!topic/tiddlywikidev/Wan8E9Q9b1U |
Currently, the
getReferringTiddlers
method ofstore
(1) (which is used to provide references (2)) uses links provided byTiddler.prototype.changed
(3) (throughTiddlyWiki.prototype.reverseLookup
(4)). Thechanged
method recognizes wikiwords, bracketed links etc via theconfig.textPrimitives.tiddlerAnyLinkRegExp
andconfig.textPrimitives.tiddlerForcedLinkRegExp
(5) RegExps. The latter don't distinguish[[some tiddler##section]]
link-like expressions which can be used intiddler
and other macros. This causes the situation whensome tiddler
's references don't show the tiddler where the transclusion is used (if there's a tiddler namedsome tiddler##section
then its references list shows the macro-containing tiddler).So, to fix this, either
changed
method orgetReferringTiddlers
method sholud be changed. It seems reasonable to changechanged
method by adding a helper inside it: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
The text was updated successfully, but these errors were encountered: