What is the best way to create jump links?

I have tried most of the ways I know of constructing markdown jump links such as
[Jump to target](#targetID) or [jump to target][target]
where the target ID is a markdown header.

It’s not working for me in Preview (or in Link mode).

I am set to use Multimarkdown but I have tried GHM also.

What am I missing here…?

1 Like

A workaround would be to code the target in HTML.

Yeuch! But I’m not sure Markdown has the syntax to do better.

I do not believe Markdown has syntax for creating anchors directly. The [jump to target](#targetID) will generate a valid link to an HTML anchor in the document, but you would have to put in the raw HTML <a name='targetID'></a> where you want it to jump to…if you did, that would work fine in Previews.

Here’s a special preview action that should help.

If I’ve got this right, it should take your draft content, find the headings, add in the appropriately formatted anchor elements (leaving your original draft content untouched), then pass it on (via a custom template tag) to a preview step. It worked fine for a couple of quick test cases I tried, but it has not been extensively tested.

I’ve seen the format used on GitHub, but I think it’s tied into the wiki support rather than it being in the GitHub Markdown spec.; but I’ve not dug into it deeply. But if you are passing the draft content on to something that supports the auto-generation of anchored links for headings, then this preview should help you check it, or simply allow you to use it as linked without leaving the app.

Hope that helps.

Hi Stephen

Thank you for contributing the Preview Anchored Headings action.

This saves cluttering up the draft with added tags. It works really well to navigate – to the first heading only.

For some reason, subsequent headings show as headings but do not navigate. Whatever I make the subsequent heading…

Ian Greig

It seemed to be working for me, but I’ve made a couple of tweaks that will hopefully help around what I think it might (:man_shrugging:t2:) have been that you were seeing.

Specifically I’ve switched the anchor to utilise name rather than ID, and to put it on a line above the heading rather than following it.

The same action directory link should get you the updated action.

Here’s the draft I’m using for testing this. If you have any issues with your own, try this one. If you are still having issues, it may turn out to be something to do with the differences between our Markdown options or such like, so we can always compare at that point if required.

Expand to reveal test draft contents

You might well have to scroll the draft below to get everything. There are some long paragraphs. It begins with a table of contents, followed by a nursery rhyme, followed by some lorem ipsum text containing three of the headings (the contents at the start has one), and ending with some Moby Dick.


# Table of Contents
- [link to first heading](#first-heading)
- [link to middle heading](#middle-heading)
- [link to final heading](#last-heading)

Twinkle, twinkle, little star,  
How I wonder what you are.  
Up above the world so high,  
Like a diamond in the sky.

When the blazing sun is gone,  
When he nothing shines upon,  
Then you show your little light,  
Twinkle, twinkle, all the night.

Then the traveller in the dark,  
Thanks you for your tiny spark,  
He could not see which way to go,  
If you did not twinkle so.

In the dark blue sky you keep,  
And often through my curtains peep,  
For you never shut your eye,  
‘Till the sun is in the sky.

As your bright and tiny spark,  
Lights the traveller in the dark.  
Though I know not what you are,  
Twinkle, twinkle, little star.

Twinkle, twinkle, little star.  
How I wonder what you are.  
Up above the world so high,  
Like a diamond in the sky.

Twinkle, twinkle, little star.  
How I wonder what you are.  
How I wonder what you are.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus eget neque nec ipsum ultrices ultricies et a tellus. Quisque molestie leo purus, vitae imperdiet orci. Pellentesque mauris turpis, eleifend at lobortis eget, lacinia vitae lectus. Praesent nec elit nunc, nec molestie nisl. Suspendisse facilisis mi vitae nisi sollicitudin ut imperdiet elit rhoncus. Etiam interdum cursus purus, ut pharetra enim adipiscing faucibus. Nulla malesuada aliquam sollicitudin. Integer imperdiet accumsan iaculis. Quisque fermentum, lorem condimentum convallis auctor, erat sapien egestas sem, et rutrum diam nunc eu mauris. Etiam quis urna et velit euismod mollis. Morbi congue orci eu purus facilisis id hendrerit dui malesuada. Nulla nisi nisl, scelerisque eu euismod faucibus, scelerisque et lectus. Maecenas consectetur tristique justo ut venenatis. Nulla facilisi.

# First Heading
[Back to top](#table-of-contents)  
Nullam ac magna lectus. Phasellus rhoncus tempus orci at fringilla. Nullam at pulvinar orci. Phasellus tempor, turpis ac iaculis sagittis, sem nunc elementum nunc, placerat pulvinar urna dui quis enim. Etiam sollicitudin pretium tempor. Ut cursus rhoncus odio, sed eleifend risus pretium eu. Fusce eu enim quis nisi pellentesque lacinia. Nulla faucibus blandit orci eu viverra. Donec vestibulum tempus facilisis. Ut et justo quis massa suscipit feugiat. Phasellus sagittis scelerisque tincidunt. Donec diam quam, semper eget aliquam vel, vehicula vitae erat. Morbi tortor mauris, sodales id tristique vel, feugiat vitae tortor. Etiam a elit nunc, id malesuada diam. Nam nisi mauris, luctus nec sodales vitae, mollis eu risus.

## Middle Heading
[Back to top](#table-of-contents)  
Sed in nunc nulla, at convallis nisi. Suspendisse consequat euismod vestibulum. Donec dictum, est et feugiat faucibus, metus nisl pellentesque enim, a posuere orci lectus volutpat mi. Praesent lectus lorem, sodales sit amet accumsan a, placerat quis est. Maecenas non arcu sit amet magna aliquet sagittis sit amet quis orci. Nam eget ante tortor. Suspendisse lorem leo, imperdiet nec ultrices vel, bibendum ac urna. Aliquam erat volutpat. In at nisi neque, eu pharetra sem. Sed nunc tellus, laoreet fringilla tempor vitae, varius dapibus sem. Vestibulum id tortor sit amet enim varius vehicula quis non justo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Morbi tempus metus vel leo viverra non dictum dolor pharetra. Etiam auctor pretium mauris at mollis. Suspendisse enim diam, dapibus et pulvinar vitae, commodo et leo. Aenean risus dui, porttitor at gravida vitae, viverra in libero. Mauris ultrices arcu eu nulla consequat dapibus. Aenean ac nunc at ipsum tempor aliquam. Nunc purus metus, mattis eu venenatis non, egestas in mauris. In sed nulla a diam sodales auctor. Praesent at nulla aliquam felis fringilla ullamcorper. Suspendisse at ante nibh, a imperdiet metus. Nulla facilisi. Donec urna ipsum, feugiat in sagittis et, laoreet ac nunc. Etiam ut diam massa. Cras sed dui ut metus rhoncus rhoncus.

# Last Heading
[Back to top](#table-of-contents)  
Vivamus mollis convallis laoreet. Ut gravida massa quis libero pretium ut convallis velit pellentesque. Aenean bibendum venenatis pharetra. Cras ligula massa, fermentum nec imperdiet at, ultrices non urna. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Quisque vestibulum, ligula at faucibus lacinia, nisl massa fermentum tortor, ut pharetra eros eros nec neque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi cursus pretium libero ac aliquam. Quisque interdum augue at nibh porta vel rutrum quam lacinia. Aenean neque ligula, tempus a vestibulum sit amet, sollicitudin nec nisl. Duis facilisis libero mauris, blandit fringilla mi.

Call me Ishmael. Some years ago--never mind how long precisely --having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen, and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people's hats off--then, I account it high time to get to sea as soon as I can.
This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me. There now is your insular city of the Manhattoes, belted round by wharves as Indian isles by coral reefs--commerce surrounds it with her surf.

Right and left, the streets take you waterward. Its extreme down-town is the battery, where that noble mole is washed by waves, and cooled by breezes, which a few hours previous were out of sight of land. Look at the crowds of water-gazers there. Circumambulate the city of a dreamy Sabbath afternoon. Go from Corlears Hook to Coenties Slip, and from thence, by Whitehall northward. What do you see?--Posted like silent sentinels all around the town, stand thousands upon thousands of mortal men fixed in ocean reveries. Some leaning against the spiles; some seated upon the pier-heads; some looking over the bulwarks glasses! of ships from China; some high aloft in the rigging, as if striving to get a still better seaward peep. But these are all landsmen; of week days pent up in lath and plaster--tied to counters, nailed to benches, clinched to desks. How then is this? Are the green fields gone? What do they here? But look! here come more crowds, pacing straight for the water, and seemingly bound for a dive. Strange! Nothing will content them but the extremest limit of the land; loitering under the shady lee of yonder warehouses will not suffice. No. They must get just as nigh the water as they possibly can without falling in. And there they stand--miles of them--leagues. Inlanders all, they come from lanes and alleys, streets and avenues, --north, east, south, and west. Yet here they all unite. Tell me, does the magnetic virtue of the needles of the compasses of all those ships attract them thither? Once more. Say, you are in the country; in some high land of lakes. Take almost any path you please, and ten to one it carries you down in a dale, and leaves you there by a pool in the stream. There is magic in it. Let the most absent-minded of men be plunged in his deepest reveries--stand that man on his legs, set his feet a-going, and he will infallibly lead you to water, if water there be in all that region. Should you ever be athirst in the great American desert, try this experiment, if your caravan happen to be supplied with a metaphysical professor. Yes, as every one knows, meditation and water are wedded for ever.

Hi Stephen,

Your trial draft works perfectly on my Drafts – Mac and iOS. Thank you so much.

–IanG