Page MenuHomePhabricator

Embed anchor in remark up text and later link to it.
Open, WishlistPublic

Tokens
"Love" token, awarded by mcorteel."Like" token, awarded by claudiof."Baby Tequila" token, awarded by yelirekim.
Assigned To
None
Authored By
wotte, Jan 2 2014

Description

Remarkup should provide a way to embed an anchor in text, and later link to this anchor. This would be most useful in the case of Phriction documents. I could envision the syntax looking something like this:

#Anchor_Name#

I could later link to this anchor in the same document:

[[ #Anchor_In_This_Document ]]

or to an anchor in another document:

[[ SomeOtherDocument#Anchor_Name ]]
[[ SomeOtherDocument#Anchor_Name | please see the documentation here ]]

Event Timeline

wotte created this task.Jan 2 2014, 3:23 PM
wotte raised the priority of this task from to Needs Triage.
wotte updated the task description. (Show Details)
wotte added a project: Remarkup.
wotte added a subscriber: wotte.

A couple of general thoughts here:

  • The proposed #anchor# syntax might not be ideal, since it rubs up against a lot of similar syntax: #anchor is "project Anchor", ##anchor## is "monospaced text", # anchor is "ordered list item", and # anchor # may be "markdown-style header" at some point.
  • We already generate anchors for headers on wiki pages, and linking to them already works (e.g. [[test page#derp-code]] produces this: test page). How much of your use case does this cover? Maybe we could just somehow make this more obvious?
  • There are some vague issues with multiple anchors with the same name and anchors with names conflicting with page anchors in contexts like comment threads. I think these can be ignored for the most part, but they're maybe worth mentioning.
wotte added a comment.Jan 2 2014, 7:49 PM

The proposed #anchor# syntax might not be ideal, since it rubs up against a lot of similar syntax: #anchor is "project Anchor", ##anchor## is "monospaced text", # anchor is "ordered list item", and # anchor # may be "markdown-style header" at some point.

Sure, that was just an example. I kinda realized that shortly after I submitted. I'd imagine that we could use some other special character.

We already generate anchors for headers on wiki pages, and linking to them already works (e.g. [[test page#derp-code]] produces this: test page#derp-code). How much of your use case does this cover? Maybe we could just somehow make this more obvious?

Kinda-sorta-not-really. I see three problems:

  1. It's not obvious
  2. If I change the header title, all of my links to that break immediately.
  3. Long header names are truncated in a not obvious way.

There are some vague issues with multiple anchors with the same name and anchors with names conflicting with page anchors in contexts like comment threads. I think these can be ignored for the most part, but they're maybe worth mentioning.

You could probably avoid most of that by prefixing the actual anchor name with a known string, e.g., phab-user-anchor-Anchor_Name. That would probably break some stuff too in other ways.

wotte added a comment.Jan 2 2014, 7:50 PM

Oh, and

  1. I may want to be able to link to, for example, a table (which is not a section title)

Yeah, those arguments seem reasonable.

Since [[ page#anchor ]] already works, I think we just need to decide on a syntax. The most general syntax would be:

{anchor, name=whatever}

This leaves room for expansion (although I'm not sure what other attributes we'd want to put on an anchor), but is relatively verbose. I don't immediately see a simple #-based syntax which isn't ambiguous because of the large number of other #-based rules we have now or are likely to have in the future.

Maybe we can start with the verbose version?

chad triaged this task as Wishlist priority.Nov 2 2014, 11:04 PM

For easier onboarding of new users and better discoverability of anchor links in general, how about adding an extra character like "¶" at the end of a heading when hovering over it? This would make it very easy to copy an anchor. An example from the issue tracker Trac:

Or check it out here: https://trac.edgewall.org/wiki/WikiFormatting

Sam2304 added a subscriber: Sam2304.EditedJun 2 2016, 5:18 PM

This appears to have had a regression at some point

We already generate anchors for headers on wiki pages, and linking to them already works (e.g. test page produces this: test page#derp-code). How much of your use case does this cover? Maybe we could just somehow make this more obvious?

The above link doesn't take me anywhere anymore, on my install it returns a 404 (which weirdly the above link doesn't do...)

e.g. test page doesn't take me to the correct anchor...

EDIT - Correcting the anchor made no difference: test page

Interestingly,

[[test page#derp-code]] leads to: https://secure.phabricator.com/w/test_page/#derp-code/

This doesn't seem to work, but the same address without the trailing / does:

Broken:
https://secure.phabricator.com/w/test_page/#derp-code/

Working:
https://secure.phabricator.com/w/test_page/#derp-code

iiam

avivey added a subscriber: avivey.Jun 2 2016, 6:50 PM

and this is what the feed entry for the previous comment looks like:

+1 we just discovered this issue and ended up here

(broken wiki links everywhere)

Specifically, the issue you're hitting is that [[ x#y ]] and variants thereof generate garbage output?

Yes. [[ x#y ]] or [ x#y | some text ] results in a link to /x/#y/ which doesn't actually link to the anchor.

It just loads to the top of the page normally rather than to the anchor point.

avivey removed a subscriber: avivey.Jun 8 2016, 8:07 PM

I think that's fixed in HEAD now. I pushed it here, let me know if you catch any cases which still misbehave.

mcorteel added a subscriber: mcorteel.