[Link][section] to other sections doesn't work

Giannis G's Avatar

Giannis G

02 Sep, 2023 02:35 PM

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

  1. Support Staff 1 Posted by Brett on 02 Sep, 2023 07:17 PM

    Brett's Avatar

    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. 2 Posted by Giannis G on 03 Sep, 2023 04:36 PM

    Giannis G's Avatar

    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

  3. Support Staff 3 Posted by Brett on 03 Sep, 2023 06:28 PM

    Brett's Avatar

    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. 4 Posted by mazal on 04 Nov, 2024 01:27 AM

    mazal's Avatar

    A little more information to add to the discussion.

    My tests:

    ## h2 header

    [section heading in doc](#h2-header)

    • This feature works well with Discount (GFM) processor w/in the Marked2 app.
    • With Discount (GRM) exporting HTML files supported section-linking in the browser (Chrome.)
    • Feature not at all supported with MultiMarkdown processor.
    • With MultiMarkdown, the feature failed in the browser with HTML file export.
    • Other preview/render/editor apps that do not support the feature are MacDown and Obsidian. Actually, I haven't found another app supporting this feature—although some are less clear about previewing/rendering. And none let me access/switch processors (that I can see.)

    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.

    h2 header
    ------------
    
  5. Support Staff 5 Posted by Brett on 04 Nov, 2024 02:29 AM

    Brett's Avatar

    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. 6 Posted by mazal on 04 Nov, 2024 05:23 AM

    mazal's Avatar

    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.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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