[Link][section] to other sections doesn't work
Hello,
I've been using Marked 2 for years to work on individual files and it has always been a superb companion!
I recently realised I can use it to work on multiple interconnected files, creating a personal wiki on my computer. I connect one file to the other via links in the form of [text link](file_name.md)...
and this works great.
However, when I try to connect to specific headings of either another or the very same file, the linking doesn't work. I've tried:
Go to [Section 1][section1]...
### Section 1 [section1]
...
... and it doesn't work. (The link appears, but when I click it, I don't "travel" to Section 1.
The only form that works within the same file is this:
<a id="section1"></a>
### Section 1
...
Go to [Section 1](#section1).
Although it's disappointing that the [link text][section-id] form doesn't work, I would be ok using the <a id=...>
form if it actually worked to link to specific sections of other files, as in Go to the [Roman](history.md#roman) section.
Unfortunately, it doesn't.
I'm using Multi-Markdown.
TL;DR:
- Why does this form not work:
Go to [Section 1][section1]
? - How can I link to sections of other files?
Many thanks
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Brett on 02 Sep, 2023 07:17 PM
Adding an id to a header does not create a link reference, so you always
need to use the format `[link text](#section)` and not `[link
text][section]`. If you do that, the sections should be navigable within
a document.
Because Marked is not a fully-fledged web browser, it can only respond
to opening a file, not opening a file and targeting a specific section.
`[link text](file.md#section)` isn't going to work within Marked, but
`[link text](file.html#section)` would work in exported documents.
-Brett
On 2 Sep 2023, at 9:38, Giannis G wrote:
2 Posted by Giannis G on 03 Sep, 2023 04:36 PM
Hi Brett,
Thank you for your prompt and clarifying response!
Regarding the first part of your answer, do I explicitly have to use the `<a id=...>` syntax over the target heading and not the `### Heading [heading-id]` one?
Regarding the second part: this is not something that will be implemented in the future from your end, right?
Best,
Giannis
Sent from my iPhone
Support Staff 3 Posted by Brett on 03 Sep, 2023 06:28 PM
Using [id] after a headline generates an ID, which functions the same as manually inserting a name tag with id. So that part is unnecessary.
And correct, Marked will likely never function as a fully-fledged web browser. Though I’m willing to look into this further if time allows.
- Brett
On Sep 3, 2023 at 11:36 AM -0500, Giannis G <[email blocked]>, wrote:
4 Posted by mazal on 04 Nov, 2024 01:27 AM
A little more information to add to the discussion.
My tests:
## h2 header
[section heading in doc](#h2-header)
These were local server tests. I haven't tried it on a production server or public-facing pages like GitHub Pages, nor have I tested other browsers and configurations. I'd also like to dig into the HTML a bit to see how it's rendered—when it does and doesn't work via export. More or less, this feature is poorly supported across the board, although I'm happy to report that it can work with Marked2 in the correct configuration!
NOTE: This header style will also work correctly in the scenarios described.
Support Staff 5 Posted by Brett on 04 Nov, 2024 02:29 AM
MultiMarkdown generates different header ids than GFM, so links with spaces have to be linked differently depending on the processor.
Thanks,
Brett
On Nov 3, 2024 at 7:27 PM -0600, mazal <[email blocked]>, wrote:
6 Posted by mazal on 04 Nov, 2024 05:23 AM
Oh, wow. I can't remember where I got my sample from—but it didn't occur to me to test no spaces. I thought the dash took care of it. Lol.
A
## Section Header
[link text-1](#section-header)
B
## AnotherSectionHeader
[link text-2](#anothersectionheader)
C
## A-Third-Section-Header
[link text-3](#a-third-section-header)
So, A, B, C work with GFM, and B, C work with MultiMarkdown. Fantastic tip. More or less use one-word headers in production, for processing with MultiMarkdown. Thank you for the reply!
Edit: B, C also works in Obsidian but not MacDown.