Gatsby: Possible to create markdown anchors that jump to a position on the page when clicked?

Created on 18 Feb 2018  Â·  3Comments  Â·  Source: gatsbyjs/gatsby

Description

Hi, is there some way to create anchor markdown elements which jumps to a specific position on the page?

[Jump to Content](#content)

# Content

Expected behavior

I would like clicking the Jump to Content link to scroll the # Content heading into the page. I would also like navigating to the https://my-site-url/page-path/#content to automatically scroll the element into the page!

I've tried out the same markdown document on a GitHub markdown page, and it behaves as expected! (link to sample gist here)

I've looked at #386 and #302 with anchorate but it doesn't seem to work. Do I need to pass some special options to gatsby-transformer-remark in my gatsby-config.js to do this?

Thanks!!

Environment

Gatsby version: 1.9.158
Node.js version: v8.9.1
Operating System: macOS 10.13.3

I'm also just following the starter with gatsby-transformer-remark 1.7.28 to do this.

question or discussion

Most helpful comment

There is already a plugin to link headers:

https://www.gatsbyjs.org/packages/gatsby-remark-autolink-headers/

I use it together with the Markdown TOC plugin in VS Code

All 3 comments

There is already a plugin to link headers:

https://www.gatsbyjs.org/packages/gatsby-remark-autolink-headers/

I use it together with the Markdown TOC plugin in VS Code

Ah great, I didn't know this. Thanks a lot @mpolinowski !

Is it possible to remove the hovering icon left to the heading?

My options look like this:

{
         resolve: `gatsby-remark-autolink-headers`,
         options: {
         offsetY: `100`,
         icon: false,
         className: false,
         maintainCase: true,
         removeAccents: true,
},
Was this page helpful?
0 / 5 - 0 ratings

Related issues

benstr picture benstr  Â·  3Comments

andykais picture andykais  Â·  3Comments

hobochild picture hobochild  Â·  3Comments

dustinhorton picture dustinhorton  Â·  3Comments

theduke picture theduke  Â·  3Comments