1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-08 06:43:49 +00:00

feat: allow static site jumping

This commit is contained in:
linonetwo 2024-10-02 21:10:21 +08:00
parent b34221aadf
commit d2a18b4668
2 changed files with 6 additions and 4 deletions

View File

@ -3,12 +3,11 @@ title: $:/core/modules/widgets/block-mark.js
type: application/javascript type: application/javascript
module-type: widget module-type: widget
An invisible element with block-mark id metadata. An invisible element with block mark id metadata. Marking a block level element, so that it can be jumped to.
\*/ \*/
var Widget = require("$:/core/modules/widgets/widget.js").widget; var Widget = require("$:/core/modules/widgets/widget.js").widget;
var BlockMarkWidget = function(parseTreeNode,options) { var BlockMarkWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options); this.initialise(parseTreeNode,options);
// only this widget knows target info (if the block is before this node or not), so we need to hook the focus event, and process it here, instead of in the root widget.
}; };
BlockMarkWidget.prototype = new Widget(); BlockMarkWidget.prototype = new Widget();
@ -23,6 +22,8 @@ BlockMarkWidget.prototype.render = function(parent,nextSibling) {
this.idNode = this.document.createElement("span"); this.idNode = this.document.createElement("span");
this.idNode.setAttribute("data-block-mark-id",this.blockMarkId); this.idNode.setAttribute("data-block-mark-id",this.blockMarkId);
this.idNode.setAttribute("data-block-mark-title",this.tiddlerTitle); this.idNode.setAttribute("data-block-mark-title",this.tiddlerTitle);
// id for anchor jumping in static site
this.idNode.setAttribute("id",this.tiddlerTitle + "-" + this.blockMarkId);
// if the actual block is before this node, we need to add a flag to the node // if the actual block is before this node, we need to add a flag to the node
if(this.previousSibling) { if(this.previousSibling) {
this.idNode.setAttribute("data-block-mark-previous-sibling","true"); this.idNode.setAttribute("data-block-mark-previous-sibling","true");

View File

@ -92,6 +92,7 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
} }
// Set an href // Set an href
var wikilinkTransformFilter = this.getVariable("tv-filter-export-link"), var wikilinkTransformFilter = this.getVariable("tv-filter-export-link"),
to = this.toBlockMark ? this.to + "-" + this.toBlockMark : this.to,
wikiLinkText; wikiLinkText;
if(wikilinkTransformFilter) { if(wikilinkTransformFilter) {
// Use the filter to construct the href // Use the filter to construct the href
@ -102,8 +103,8 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
// Expand the tv-wikilink-template variable to construct the href // Expand the tv-wikilink-template variable to construct the href
var wikiLinkTemplateMacro = this.getVariable("tv-wikilink-template"), var wikiLinkTemplateMacro = this.getVariable("tv-wikilink-template"),
wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$"; wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$";
wikiLinkText = $tw.utils.replaceString(wikiLinkTemplate,"$uri_encoded$",$tw.utils.encodeURIComponentExtended(this.to)); wikiLinkText = $tw.utils.replaceString(wikiLinkTemplate,"$uri_encoded$",$tw.utils.encodeURIComponentExtended(to));
wikiLinkText = $tw.utils.replaceString(wikiLinkText,"$uri_doubleencoded$",$tw.utils.encodeURIComponentExtended($tw.utils.encodeURIComponentExtended(this.to))); wikiLinkText = $tw.utils.replaceString(wikiLinkText,"$uri_doubleencoded$",$tw.utils.encodeURIComponentExtended($tw.utils.encodeURIComponentExtended(to)));
} }
// Override with the value of tv-get-export-link if defined // Override with the value of tv-get-export-link if defined
wikiLinkText = this.getVariable("tv-get-export-link",{params: [{name: "to",value: this.to}],defaultValue: wikiLinkText}); wikiLinkText = this.getVariable("tv-get-export-link",{params: [{name: "to",value: this.to}],defaultValue: wikiLinkText});