Anchor Links in Newsletters

745 views
Skip to first unread message

Casey Watts

unread,
Jul 20, 2013, 1:20:06 PM7/20/13
to markdo...@googlegroups.com

Hi Markdown-Here group,

I just made a discovery! Apparently you can totally include anchor links in emails via markdown-here. In particular, for a newsletter‘s table of contents. I have a friend who distributes a newsletter whose content comes from an excel spreadsheet. I’m encouraging her to turn the spreadsheet into markdown to format it using markdown-here. One of her newsletter requirements is a table of contents with anchor links at the top.

Campaign monitor did a review of which clients support anchor links in which ways. It was posted in 2010, but it still seems up to date for gmail at least.

Here's an example of anchorlink functionality:

[Title of Section 1](#nameoflink)
[Title of Section 2](#nameoflink2)
[Title of Section 3](#nameoflink3)
[Title of Section 4](#nameoflink4)
[Title of Section 5](#nameoflink5)

#Header
content

#Header
content

#Header
content

#Header
content

#Header
content

#Header
content

#Header
content

#Header
content

#<a name="nameoflink1"></a>Title of Section 1
content

#<a name="nameoflink2"></a>Title of Section 2
content

#<a name="nameoflink3"></a>Title of Section 3
content

#<a name="nameoflink4"></a>Title of Section 4
content

#<a name="nameoflink5"></a>Title of Section 5
content
-- 
Casey!

Adam Pritchard

unread,
Jul 23, 2013, 9:02:46 AM7/23/13
to markdo...@googlegroups.com

Nice one, Casey. Thanks.

Some day there might be a solution that doesn't require the use of raw HTML. For example, Marked.js (the MD lib that MDH uses for rendering) currently has multiple outstanding pull requests (e.g., #117, #181) for adding IDs to headers, which would facilitate the anchors.

Although… then the MDH user would have to guess what the generated anchor ID/name is in order to refer to it. Not very user friendly. Better if the user could specify it, as happens in your example.

There are also outstanding Marked.js issues and pull requests for adding custom hooks to rendering, which could probably be used to have a cleaner interface. (It would effectively mean deviating from the MD spec again, which puts me off for a moment, but… I'd probably still do it.)

Casey Watts

unread,
Jul 23, 2013, 9:30:48 AM7/23/13
to markdo...@googlegroups.com

It would be exciting to avoid raw HTML! Unfortunately, gmail strips out IDs so those pull requests aren't nearly as exciting. We have to use the name attribute on the <a> tag in order to preserve it through gmail.

We could probably come up with an easy enough syntax where a link like [linkname](#Name Of Section) would convert to a dash-separated sting or something, and link to #Name Of Section. The reverse of whatever the Marked.js convention would be. I guess it would actually be best of both sides were in Marked.js directly.

I do think we have a ‘need’ for something more extensible for rendering. I define classes in an external CSS file, but there's no way to call them without the HTML tag <div class="classname"> (I end up doing quite a bit of this on my markdown-based blog - it's better than writing the entire thing in HTML! lol).

-- 

Casey Watts
Assistant Manager, Student Technology Collaborative

Adam Pritchard

unread,
Aug 7, 2013, 10:20:23 PM8/7/13
to markdo...@googlegroups.com

For the record, Marked.js went with the id attribute and not name: https://github.com/chjj/marked/pull/181 So… no good to us.

I have creating an issue for anchor links here: https://github.com/adam-p/markdown-here/issues/93

And, yes, extensible rendering would be great. The Marked.js guy mentions it every now and then, but… dunno. I‘ll keep it in the back of my mind and see if I can come up with something. (But I’m not gonna lie: Every time I deviate from standard MD I suffer for it with bugs and confusion. But still, it'd be great.)

Adam

Casey Watts (Personal)

unread,
Aug 8, 2013, 1:05:59 PM8/8/13
to Adam Pritchard, markdo...@googlegroups.com
We're really in the weeds here lol - where Marked.js and GMail aren't agreeing, and we're trying to mediate. It might be best to ignore this problem until either one changes, or at least mark it as a lower priority. Or to fila a request with Marked.js, but I'm not sure what specifically we could ask of them. To have both id and name, would that be silly?


Casey!


--
You received this message because you are subscribed to a topic in the Google Groups "markdown-here" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/markdown-here/eaq1JoNhyws/unsubscribe.
To unsubscribe from this group and all its topics, send an email to markdown-her...@googlegroups.com.
To post to this group, send email to markdo...@googlegroups.com.
Visit this group at http://groups.google.com/group/markdown-here.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Adam Pritchard

unread,
Aug 8, 2013, 2:52:34 PM8/8/13
to markdo...@googlegroups.com, Adam Pritchard

I tried to get them to add both! And failed. (First try, second try.)

I really don't think either Gmail or Marked will change in this regard. So… Maybe we should just hack Marked.js some more. If you look for “adam-p” in MDH's copy of marked.js you can see that I already alter the file. The Marked.js #181 diff suggests that I'd just have to change one one word.

Or… maybe name and id should be present, since MDH is kinda/sorta not just an email thing. This is yet another example of how different sites/users need different code/styling.

Updated the issue and targeted to next release.

guid...@gmail.com

unread,
Jan 20, 2014, 12:19:31 PM1/20/14
to markdo...@googlegroups.com
Is there any option to remove/deactivate the automated addition of anchors to headers?

https://github.com/adam-p/markdown-here/commit/83aa9c476f36bc64fd03187de505e2c054a732d0

Adam Pritchard

unread,
Jan 20, 2014, 10:09:47 PM1/20/14
to markdo...@googlegroups.com, guid...@gmail.com
There can be. What is it that you don't like about the header anchors? 

(Let me guess: The placeholders in Thunderbird?)


Adam

guid...@gmail.com

unread,
Jan 21, 2014, 4:25:57 AM1/21/14
to markdo...@googlegroups.com, guid...@gmail.com
Yes, it clutters the preview and wastes a lot of space in Thunderbird.

https://www.evernote.com/shard/s30/sh/dcebbed7-34a0-4e91-a74b-71f5fd119fa4/d9ba8a9fdce630e7f0a64e902f9a13d9

Guido
Reply all
Reply to author
Forward
0 new messages