Closed somidad closed 7 months ago
The recent update focuses on refining the process of creating markdown links, specifically adjusting how anchor tags are generated. By amending the assignment of the anchor
variable to prepend "user-content-"
to anchors instead of the previous #^
, the change ensures smoother and more standardized link creation within markdown documents.
File(s) | Summary of Changes |
---|---|
src/conversion/links.ts |
Updated the createMarkdownLinks function to modify anchor tag generation. |
🐰✨
In the realm of code, where links intertwine,
A rabbit hopped, making markdowns refine.
"With a hop, a skip, a magical tweak,
Let 'user-content-' lead the way, unique.
So, celebrate this change, both big and small,
For it makes a difference, after all."
🌟📝
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
In addition, I think it would be better if:
user-content-
shall be configurable, whereas I hardcoded itI'm sorry but I really don't understand what so you want. Is a feature used of a specific template?
I wanted/tried to implement Link to a block in a note
If I have the following in a note, Obsidian makes me navigate to the indicated block:
This is a paragraph ^24fe22e
Go to [[#^24fe22e|the paragraph]]
But AFAIK, this plugin does not support it yet.
So I first add text conversion from ^identifier
to <a id="^identifier"></a>
and I thought a link to this anchor would work.
But later I found that GitHub adds a prefix user-content-
to the ID.
So this is my proposal to add the prefix to a link.
What do you mean github add a prefix to the ID? You use github directly to publish your file? Github doesnt support [[^xxx]] syntaxe. That's not a lack on support on my side but on github side.
I use this plugin to publish the file. This plugin converts wikilink ([[note#^anchor]]
) to html link (<a href="note_url#^anchor">alt_text</a>
).
But this plugin leaves ^anchor
(at the end of paragraph, not in link) as-is. So I configured text conversion to do this (^anchor
to <a id="^anchor"></a>
)
And if the file is published, GitHub adds the prefix so <a id="^anchor"></a>
becomes <a id="user-content-^anchor"></a>
. You can see the sample link above. When you inspect the html, you can see ID of user-content-...
. I didn't write that prefix at the time I wrote the note.
So it could be interesting to have an option to convert block-id link to html link with configurable id?
Yes, kind of.
Since this project (plugin) is specific to "Obsidian" and "GitHub", I think the proposed changes and additional proposal (converting ^anchor
to <a id="^anchor"></a>
) is not that unreasonable.
Ah, never mind. I found the following configuration does well what I intended:
"censorText": [
{
"entry": "/ (\\^\\w+)$/gm",
"replace": " <a id=\"$1\"></a>",
"flags": "",
"after": true
},
{
"entry": "/#(\\^\\w+)\\)/gm",
"replace": "#user-content-$1)",
"flags": "",
"after": true
}
]
This proposal converts
[[note#^identifier]]
into[altLink](note#user-content-^identifier)
instead of[altLink](note#^identifier)
Background
I have the following conversion. It converts a block identifier, e.g.
^37066d
at the end of a paragraph into<a id="^37066d"></a>
. (AFAIK, this plugin does not support such conversion natively.)However, when GitHub renders the file on the web browser, it add
user-content-
prefix to the ID. (I guess they try to avoid ID duplication/collision.)So a link to a block, e.g.
[[note#^identifier]]
, would not work after publishing to GitHub since such an anchor does no longer exist due to GitHub markdown renderer.Summary by CodeRabbit
"""