@@ -582,29 +582,92 @@ ea.optimize_image_attachments_to_webp('H2q3901uFDCH')
582
582
583
583
This action can save significant space if you have many clipped pages. Whoever invented ` WebP ` is a genius.
584
584
585
- ## (Advanced Usage) Automatically add internal link
585
+ ## (Advanced Usage) 🔗 Automatically Add Internal Links
586
586
587
- Experimental feature. Backup your database before do anything with this feature. It may completely destroy your notes .
587
+ This feature allows you to automatically create internal links within your notes. Let’s take a look at how it works .
588
588
589
- If you find something wrong after using this feature. Please provide me a minimal note sample to test and fix potential
590
- bugs.
589
+ ### Example
591
590
592
- Add internal link in note
591
+ Here is a sample note:
593
592
593
+ ![ auto-link-1] ( docs/auto-link-1.webp )
594
+
595
+ After running a single line of code:
596
+
597
+ ``` python
598
+ auto_create_internal_link(' put_note_id_here' )
594
599
```
595
- auto_create_internal_link('HfAnsf8XiarY')
596
- ```
597
600
598
- For multiple notes
601
+ The note transforms into this:
602
+
603
+ ![ auto-link-2] ( docs/auto-link-2.webp )
604
+
605
+ As you can see, some text has been replaced with internal links. The feature follows these rules:
606
+
607
+ - ** Title Match** : Content that matches any other note's title is replaced with an internal link.
608
+ - ** Duplicate Titles Ignored** : If multiple notes share the same title, no link is created for that title.
609
+ - ** Longer Matches First** : Longer titles take precedence. For example, in the above example, "Nate River" is linked,
610
+ not just "River."
611
+ - ** Existing Links Remain** : Pre-existing links in the text are left untouched.
612
+
613
+ However, some words like "make" and "work" in the example are part of my "English Words That I Do Not Know" note. Since
614
+ they are common and frequently used, I don’t want them to create excessive internal links.
615
+
616
+ ### Excluding Notes from Internal Linking
617
+
618
+ To prevent certain notes from being linked:
619
+
620
+ - Add the tag ` #ignoreAutoInternalLink ` to a note. This note (and optionally its sub-notes) will be excluded from link
621
+ creation.
622
+ - You can make it ** inheritable** —you can apply it to a parent note and inheritable, then it will be automatically
623
+ exclude all its sub-notes.
624
+
625
+ Here’s how it looks after applying the exclusion rule:
626
+
627
+ ![ auto-link-3] ( docs/auto-link-3.webp )
628
+
629
+ The result is cleaner and more intentional.
630
+
631
+ ### Special Case: Duplicate Titles
632
+
633
+ When multiple notes share the same title, a specific condition allows for internal links:
599
634
635
+ - ** Direct Sub-Notes Have Priority** : Direct child notes take precedence over other notes with the same title.
636
+
637
+ For instance:
638
+
639
+ ![ auto-link-4] ( docs/auto-link-4.webp )
640
+
641
+ In this case, the note ` TriliumNext ` links "How to compile" to its own child note, not the one from ` Trilium ` .
642
+
643
+ ### Final Rule: No Self-Linking
644
+
645
+ A note will never create an internal link to itself.
646
+
647
+ ---
648
+
649
+ ### Code Samples
650
+
651
+ ** Add an internal link to a specific note by its ID:**
652
+
653
+ ``` python
654
+ auto_create_internal_link(' gLmmsIM8yPqx' )
600
655
```
656
+
657
+ ** Add internal links for multiple notes:**
658
+
659
+ ``` python
601
660
auto_create_internal_link(target_notes = [' gLmmsIM8yPqx' , ' T4Ui3wNByO03' ])
602
661
```
603
662
604
- (Dangerous action, backup first) Add internal notes for all text notes
663
+ ** (Experimental - Use with Caution)**
664
+ ** Add internal links to all text notes:**
605
665
606
- ```
607
- auto_create_internal_link(prcess_all_note=True)
666
+ This is an experimental feature. ** Backup your database** before using it, as it may irreversibly modify your notes. If
667
+ issues occur, please provide a minimal note sample to help debug.
668
+
669
+ ``` python
670
+ auto_create_internal_link(process_all_notes = True )
608
671
```
609
672
610
673
## 🛠️ Develop
0 commit comments