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
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.)
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).
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
--
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.
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.