Skip to content

Anchors on figures and listings #921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
elbow-jason opened this issue Sep 12, 2017 · 7 comments
Open

Anchors on figures and listings #921

elbow-jason opened this issue Sep 12, 2017 · 7 comments

Comments

@elbow-jason
Copy link

I have noticed that there are anchor tags on sections and subsections. It would be nice to have anchor tags on the figures' names as well. For example (from the book):

Listing 5-15: Implementing the can_hold method on Rectangle that takes another Rectangle instance as a parameter

The text Listing 5-15 would be a clickable/fragment-navigable link just like sections and subsections.

@carols10cents
Copy link
Member

Yep! I've often wanted this myself. I'm not sure the best way to implement this, and since this doesn't affect print at all, it'll be a while before Steve or I has time to work on this. So if someone wants to help out on this, that would be awesome!

@pduzinki
Copy link
Contributor

I'd like to claim this one.

@Michael-F-Bryan
Copy link

Would it make sense to incorporate this into mdbook's HTML renderer? For example, whenever including images we could also automatically insert an anchor tag or id which uses a "slugified" version of the figure's alt text.

For example,

![Listing 5-15](img/listing_5_15.png)

would be translated into

<img src="img/listing_5_15.png" alt="Listing 5-15" id="listing-5-15" />

Then whenever you want to refer to that image you'd be able to use its id

For example, as seen in [Listing 5-15](#listing-5-15), blah blah blah.

cc: #1092

@carols10cents
Copy link
Member

The problem is these aren't usually images, they're code blocks, and it's not every code block :-/

@Michael-F-Bryan
Copy link

I had a feeling that'd be the case when I saw the word "listing", but it was worth a shot :)

@steveklabnik
Copy link
Member

The fix for this had to be reverted, so I'm re-opening it.

@mianlang
Copy link
Contributor

Hi everyone, I think I've added anchors to the listings in #4271. Would anyone like to review it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants