Feat: allow link to ^id anchor#7744
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
This is a minor comment: The highlighted color would be nice to follow the palette in use. |
|
Some use cases:
|
Sure, I'm using the existing
I'm not sure if this is necessary, I will auto create id on target tiddler, when you write a link in another, when using the WYSIWYG editor (or maybe codemirror-enhannced), this is the UX of Obsidian. While it is reasonable to fall back to a menu button, if user is using empty edition, but that will have a huge UX gap between Obsidian.
Yes, it can be used to write footnotes and in refnotes. But its main purpose is for block-level backlinks, and block-level transclusion, like in Obsidian. We need to have all that they have!
I think Obsidian can only transclude a single block. I'm not sure if transclude syntax can be extended to reference 2 id to create a reference... |
I think this is good to go!
That is fine. Thank you |
|
If a line started with space or tab then TW does not recognize the Note to the space before |
|
Suggestion:
|
|
The doc is at https://tiddlywiki5-git-fork-linonetwo-feat-section-mark-jermolene.vercel.app/#Block%20Level%20Links%20in%20WikiText You can modify it by PR to my branch. 1 char is enough, but I'd use 6 char hash when auto generate it. |
|
@linonetwo In the discussion #7744 you wrote, that the IDs would be "namespaced". So if the same ID is used in 2 tiddlers that are visible at the same time it would be possible to deterministically link to them. In the preview that's not the case atm. Both "instances" which render the content have enough information to make it happen. But I think it can work. and
So I think it should be possible. I'm experimenting atm. |
|
Okay, I forgot this. I think simply prefixing the id with the tiddler title is enough. But blockid ast node don't know itself is in which tiddler...So blocked widget don't know this too! Can you get title in the For the backlink scenario current implementation is enough, because we can get backlink title, then just search for the id in that tiddler's text. |
Should be possible to get the |
|
Ok, Now it works, I also update the doc to use same id in two tiddlers. Since I'm using data selector, I will use data selector for id, instead of id selector, so we can use any char in the id, like |
|
Can this totally replace the Linking within tiddlers - "anchor links" usage? |
|
|
||
| BlockIdWidget.prototype.hookNavigationAddHistoryEvent = function(event) { | ||
| // DEBUG: console this._isNavigateToHere(event) | ||
| console.log(`this._isNavigateToHere(event)`, this._isNavigateToHere(event)); |
There was a problem hiding this comment.
In the TW core we still use ES5 only. So JS template literals are not possible atm: `this._isNavigateToHere(event)`
So this code needs to be changed.
There was a problem hiding this comment.
Thanks, this is debug statement, forget to delete...
There was a problem hiding this comment.
Created by this in vscode BTW
"Print to console": {
"prefix": "lo",
"scope": "javascript,javascriptreact,typescript,typescriptreact",
"body": ["// DEBUG: console $1", "console.log(`$1`, $1);"],
"description": "Log formated JSON output and var name to console"
},
|
@CrossEye -- Can you have a closer look at this one. IMO it's related to your implementation of the permalink creation. |
Jermolene
left a comment
There was a problem hiding this comment.
Thank you @linonetwo and apologies for the delay in reviewing this.
I have a number of concerns about the complexity and brittleness of this implementation:
- The use of hooks for widgets to communicate with one another is not a technique that we use in the core. Hooks are provided for plugin developers to be able to experiment with modifications to the core behaviour without having to modify the core code. For core improvements, we can make any changes we need, and so don't need the blunt instrument of hooks
- The way that the parse rule can refer to the previous or current block is deeply confusing
- I don't understand the need for the "blockid" widget; I would expect the syntax rule for an anchor just to generate a simple
<a>element. I suspect that this is because of the way that block ids can apply to the previous block
I think it would be clearer to avoid the term "block"; in TiddlyWiki, we use the word when we're talking about parser modes, but we do not refer to blocks within tiddlers. It would be clearer to just call them "anchors".
|
Hi @linonetwo
I don't recall the details, but my current thinking is that we would only need to descend the widget tree to find the anchor widgets.
The
Yes, I think the current terminology works well. |
- Remove all temporary/marker node types and inline anchor rule - Add .utils.extractInlineAnchor(nodes) for trailing ^id detection - parseBlock, heading, and list rules now directly extract and wrap anchors - No post-processing, no marker nodes, no _anchorId, no wrapAnchors - All tests pass, lint clean BREAKING CHANGE: Only trailing ^id syntax is supported for block anchors. No more anchor-marker or inline anchor rule.
- Remove anchor.js inline rule file - Update all block rule and serializer files to match trailing ^id anchor architecture - Update all anchor-related test data and documentation - All tests pass, lint clean This commit ensures all anchor-related files are consistent with the new trailing ^id syntax and no temporary node types are used.
…chitecture Replace the dual anchorblock-rule + extractInlineAnchor approach with a clean two-layer design: 1. New inline anchor rule (anchor.js) matches trailing " ^id" on any line and emits a name anchor node — an empty placeholder consumed by the serializer to output " ^id". 2. wrapAnchorsInTree() (parsetree.js), called once at the end of parseBlock(), recursively finds name anchors inside block elements and wraps those elements in a target anchor container. Key changes: - codeblock/typedblock opening lines now parsed via parseInlineRun so inline anchor rule fires naturally (e.g. ```css ^id, $$$type ^id) - quoteblock cite parsed without skipWhitespace so " ^id" is visible to the inline rule (e.g. <<< ^id or <<< Some cite ^id) - list.js parser fully restored to origin/master (no anchor logic) - anchorblock parser rule removed; ^id-on-own-line syntax dropped - anchor widget: name anchors render nothing; target anchors render the wrapping container with data-tw-anchor / id / tabindex attributes - quoteblock serializer updated to round-trip cite + anchor - All serializers updated to use name/target anchor distinction Docs: split Block Level Links into separate Block Level Transclusion tiddler; add real anchor examples and clarify ^start..^end range syntax. Tests: 1480 specs, 0 failures
✅ Change Note StatusAll change notes are properly formatted and validated! 📝 $:/changenotes/5.5.0/#7744Type: feature | Category: hackability
🔗 #7744 👥 Contributors: linonetwo 📖 Change Note GuidelinesChange notes help track and communicate changes effectively. See the full documentation for details. |
…to ^start^end
Since anchor ids cannot contain ^, the second ^ is an unambiguous separator.
This makes {{Title^start^end}} consistent with {{Title^anchor}} — no new
delimiter characters needed.
Update parseTextReference regex, all tests, serializer, and documentation.
✅ Change Note StatusAll change notes are properly formatted and validated! 📝 $:/changenotes/5.5.0/#7744Type: feature | Category: hackability
🔗 #7744 👥 Contributors: linonetwo 📖 Change Note GuidelinesChange notes help track and communicate changes effectively. See the full documentation for details. |
|
Now, Any block can be tagged with a trailing How it works (two-layer parse)
Transclusion
No big changes to existing rules, no accessing parient widget
And now |
✅ Change Note StatusAll change notes are properly formatted and validated! 📝 $:/changenotes/5.5.0/#7744Type: feature | Category: hackability
🔗 #7744 👥 Contributors: linonetwo 📖 Change Note GuidelinesChange notes help track and communicate changes effectively. See the full documentation for details. |
…s; fix spec comment prettylink.js: tighten regex so [[Title|]] and [[Title^]] do not produce empty alias/anchor captures. Change: (?:\|(.*?)?)? -> (?:\|(.*?))? (?:\^([^|\s^]+)?)? -> (?:\^([^|\s^]+))? playwright.spec.js: update stale ..^ range syntax comment to ^start^end. Add E2E fixture tiddlers for playwright anchor tests: editions/test/tiddlers/Anchor/Marks.tid editions/test/tiddlers/Anchor/Links.tid editions/test/tiddlers/Anchor/Transclusion.tid
✅ Change Note StatusAll change notes are properly formatted and validated! 📝 $:/changenotes/5.5.0/#7744Type: feature | Category: hackability
🔗 #7744 👥 Contributors: linonetwo 📖 Change Note GuidelinesChange notes help track and communicate changes effectively. See the full documentation for details. |
This is block-level link. Prepare for block-level backlink.
(wait for #6081 so I can continue modify back-indexer)Add a new
^idsyntax, see #7537 for details.Also modify pretty wiki link's parsing rule to allow link to such an id. And modify link widget to allow id widget to react to link jumping.
(Currently, if
New Tiddleris not currently opened,hookFocusElementEventcan't highlight the element, I have to usesetTimeoutto wait for the dom element actually show. Is there a better solution?)And sadly, we can't use
#xxxas ID, otherwise will encounterInvalid selector: ##BlockLevelLinksID1Demo: https://tiddlywiki5-git-fork-linonetwo-feat-d29eaa-jermolenes-projects.vercel.app/#Block%20Level%20Links%20in%20WikiText:%5B%5BBlock%20Level%20Links%20in%20WikiText%5D%5D%20%5B%5BLinking%20in%20WikiText%5D%5D