1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-12-31 12:39:03 +00:00
Files
s793016 7c197f6ecc Fix character disappearing and false matching issues in TiddlyWiki 5.4 Freelink plugin (#9397)
* Update aho-corasick.js

False positive matches

Symptom: Words like "it is", "Choose", "Set up" are incorrectly linked to tiddler "FooBar" when a tiddler titled "xxx x FooBar" exists.

Root cause: The Aho-Corasick algorithm's output merging mechanism in buildFailureLinks caused failure link outputs to be incorrectly merged into intermediate nodes, resulting in false matches.

Fix:

Remove incorrect output merging in buildFailureLinks
Implement proper output collection during search by traversing the failure link chain
Add exact match validation: verify that the matched text exactly equals the pattern before accepting it
Add cycle detection to prevent infinite loops in failure link traversal

* Update text.js

First character disappearing

Symptom: When freelinking is enabled, the first character of matched words disappears (e.g., "The" becomes "he", "Filter" becomes "ilter").

Root cause: When the current tiddler's title was being filtered out, it was done too late in the process (during parse tree construction), causing text rendering issues.

Fix:

Move the current tiddler title filtering to the match validation stage (in processTextWithMatches)
Use substring instead of slice for better stability
Add proper case-insensitive comparison for title matching

* Update text.js

add back description

* Update aho-corasick.js

add back description

* Update tiddlywiki.info

add freelinks plugin for testing

* Update tiddlywiki.info

restore

* Update tiddlywiki.info

add freelinks plugin for test

* Update aho-corasick.js

erase comment

* Update text.js

erase comment

* Update aho-corasick.js

add back some commets

* Update aho-corasick.js

clean comment

* change note #9397

change note #9397

* Update tiddlywiki.info

reversed to original

* Update #9397.tid

update detail

* Update #9397.tid

another link added

* Update #9397.tid

add "release: 5.4.0"

* Update #9397.tid

some format modified
2025-12-17 15:02:42 +00:00
..
2020-01-04 16:33:52 +00:00

title: $:/plugins/tiddlywiki/freelinks/readme

This plugin adds automatic generation of links to tiddler titles.

The plugin uses the Aho-Corasick algorithm for efficient pattern matching with large numbers of tiddlers.

!! Configuration

Freelinking is activated for runs of text that have the following variables set:

* `tv-wikilinks` is NOT equal to `no`
* `tv-freelinks` is set to `yes`

Freelinks are case sensitive by default but can be configured to ignore case in the settings panel.

Word boundary checking can be configured in the settings panel. When enabled (default for Western languages), links are created only for complete words. When disabled, partial matches within words are also linked.

When multiple tiddler titles match the same text, longer titles take precedence over shorter ones.

Tiddlers do not create links to themselves.

Use `$:/config/Freelinks/TargetFilter` to define which tiddlers are eligible for auto-linking.

Within view templates, the variable `tv-freelinks` is automatically set to the content of `$:/config/Freelinks/Enable`, which can be set via the settings panel of this plugin.

!! Notes

To change within which tiddlers freelinking occurs requires customising the shadow tiddler [[$:/plugins/tiddlywiki/freelinks/macros/view]]. This tiddler is tagged `$:/tags/Macro/View` which means that it will be included as a local macro in each view template. By default, its content is:

```
<$set name="tv-freelinks" value={{$:/config/Freelinks/Enable}}/>
```

That means that for each tiddler the variable `tv-freelinks` will be set to the tiddler `$:/config/Freelinks/Enable`, which is set to "yes" or "no" by the settings in control panel.

Instead, we can use a filter expression to, say, only freelink within the tiddler with the title "HelloThere":

```
<$set name="tv-freelinks" value={{{ [<currentTiddler>match[HelloThere]then[yes]else[no]] }}}/>
```

Or, we can make a filter that will only freelink within tiddlers with the tag "MyTag":

```
<$set name="tv-freelinks" value={{{ [<currentTiddler>tag[MyTags]then[yes]else[no]] }}}/>
```

Or we can combine both approaches:

```
<$set name="tv-freelinks" value={{{ [<currentTiddler>match[HelloThere]] ~[<currentTiddler>tag[MyTag]] +[then[yes]else[no]] }}}/>
```

!! Implementation Details

The Aho-Corasick algorithm implementation includes:

* Unicode character support for international text
* Prevention of self-referential links within the current tiddler
* Performance safeguards including depth protection and result limiting
* Graceful fallback handling for invalid patterns

Longer tiddler titles take precedence over shorter ones when multiple matches are possible.