Skip to content
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

Automatically create anchors for section headers #72

Closed
steveklabnik opened this issue Dec 16, 2015 · 4 comments
Closed

Automatically create anchors for section headers #72

steveklabnik opened this issue Dec 16, 2015 · 4 comments

Comments

@steveklabnik
Copy link
Member

If I write something like this:

## Foo

and I want to link to it later, I have to do this:

<a href="#foo">
## Foo
</a>

or the equivalent. GitHub and rustbook generate these kinds of links automatically, which keeps source files cleaner. Example: https://github.com/rust-lang/rust/#quick-start

@azerupi
Copy link
Contributor

azerupi commented Dec 16, 2015

If I implement this in mdbook it's going to be an ugly hack, I would have to either parse the markdown a second time myself or parse the html outputted by pulldown-cmark.

I think this should be implemented in the markdown parser. But pulldown-cmark hasn't seen any activity in a while, so I doubt that is going to happen anytime soon. :/

@steveklabnik
Copy link
Member Author

Ah interesting, I should check up on pulldown-cmark.

@asolove
Copy link
Contributor

asolove commented Dec 27, 2015

Since pulldown-cmark is striving to match the CommonMark spec, I think it's unlikely they would accept a PR for this non-standard behavior. It would be pretty trivial to do this in JS after the fact, though, as long as you had a clear rule for how to turn a run of text into an anchor name that can't have spaces.

@azerupi
Copy link
Contributor

azerupi commented Dec 27, 2015

It would be pretty trivial to do this in JS after the fact

Yeah, but I had in mind that the browser wasn't going to scroll down if anchors were added after page load. Obviously I was wrong 😉 Thanks for the PR!

Since pulldown-cmark is striving to match the CommonMark spec, I think it's unlikely they would accept a PR for this non-standard behavior.

It's pretty common to add anchors to headings in web-dev, I don't understand why this isn't part of the spec yet..

And one neat thing about Rust, is that you can easily gate some parts of your code behind Features, non-standard additions could be feature-gated and off by default. :)

@azerupi azerupi closed this as completed Dec 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants