feat: allow using any char in id

This commit is contained in:
linonetwo 2023-09-17 20:11:59 +08:00
parent a5c2f8558e
commit cff0240ac8
3 changed files with 10 additions and 9 deletions

View File

@ -23,7 +23,6 @@ BlockIdWidget.prototype.render = function(parent,nextSibling) {
this.execute();
// Create an invisible DOM element with data that can be accessed from JS or CSS
this.idNode = this.document.createElement("span");
this.idNode.id = this.id;
this.idNode.setAttribute("data-block-id",this.id);
this.idNode.setAttribute("data-block-title",this.tiddlerTitle);
if(this.before) {
@ -56,7 +55,7 @@ BlockIdWidget.prototype.hookNavigatedEvent = function(event) {
};
BlockIdWidget.prototype._getTargetElement = function(baseElement) {
var selector = "#"+this.id;
var selector = "span[data-block-id='"+this.id+"']";
if(this.tiddlerTitle) {
// allow different tiddler have same block id in the text, and only jump to the one with a same tiddler title.
selector += "[data-block-title='"+this.tiddlerTitle+"']";

View File

@ -1,6 +1,6 @@
caption: block id
created: 20230916061829840
modified: 20230917120133519
modified: 20230917121007649
tags: Widgets
title: BlockIdWidget
type: text/vnd.tiddlywiki
@ -17,7 +17,7 @@ The content of the `<$blockid>` widget is ignored.
|id |The unique id for the block |
|previousSibling |`yes` means the block is before this node, in parent node's children list, else it means the block is this node's direct parent node. |
See [[Block Level Links in WikiText^block091606]] for WikiText syntax of block ID.
See [[Block Level Links in WikiText^🤗→AddingIDforblock]] for WikiText syntax of block ID.
! Example

View File

@ -1,11 +1,11 @@
caption: Block Level Links
created: 20230916061138153
modified: 20230916070710392
modified: 20230917121127276
tags: WikiText
title: Block Level Links in WikiText
type: text/vnd.tiddlywiki
! Adding ID for block ^block091606
! Adding ID for block ^🤗→AddingIDforblock
The basic syntax for block id is:
@ -13,12 +13,12 @@ The basic syntax for block id is:
# Don't forget the space between the end of the line and the `^`.
# And there is no space between `^` and the id.
# ID should be a [ext[valid HTML element ID|https://developer.mozilla.org/docs/Web/HTML/Global_attributes/id]], to avoid inadvertent errors, only ASCII letters, digits, '_', and '-' should be used, and the value for an id attribute should start with a letter.
# ID can contain any char other than `^` and space ` `.
And this block id widget will be rendered as an invisible element:
```html
<span id="BlockLevelLinksID1" data-block-id="BlockLevelLinksID1" class="tc-block-id"></span>
<span class="tc-block-id" data-block-id="BlockLevelLinksID1" data-block-title="Block Level Links in WikiText"></span>
```
!! Adding id to previous block
@ -41,4 +41,6 @@ Adding `^blockID` after the title in the link, will make this link highlight the
<<wikitext-example-without-html src:"[[Link to BlockLevelLinksID1|Block Level Links in WikiText^BlockLevelLinksID1]]">>
<<wikitext-example-without-html src:"[[Link to BlockLevelLinksID2|Block Level Links in WikiText^BlockLevelLinksID2]]">>
<<wikitext-example-without-html src:"[[Link to BlockLevelLinksID2|Block Level Links in WikiText^BlockLevelLinksID2]]">>
<<wikitext-example src:"[[Link to Title|Block Level Links in WikiText^🤗→AddingIDforblock]]">>