does fireball markdown support anchor links?

Michel Fortin michel.fortin at michelf.ca
Thu Jul 9 10:15:50 EDT 2015


Le 2015-07-09 à 0:30, Alan Hogan <contact at alanhogan.com> a écrit :
> Furthermore, auto-gen'd headers *will* break when the text of the header is changed, which can be done for any number of innocuous reasons when we would like the link to be preserved. (Cool URIs don’t change, right?)
>  
> For that reason, I have always been a fan of the ID specification syntax that pandoc, PHP Markdown Extra, maruku, kramdown, and a few others support:
>  
> 	## This is a header         {#a-header}
>  
> which compiles to:
>  
> 	<h2 id="a-header">This is a header</h2>
>  
> Look at that! Cleaner Markdown *and* cleaner output than inserting your own <a> tag. And better, more future-proof section IDs than the auto-generated variety.
> 
> Sadly, I never get to use it, due to the regrettable and totally predictable fact that so many Markdown converters ignore it.
>  
> Not to pick on showdown, but look at its output:
> <h2 id="thisisaheaderaheader">This is a header {#a-header}</h2>

Yeah, this is sad.

I'll just point out that PHP Markdown Extra does support automatic generation of headers id as long as you provide it with a proper function to generate the id from the content of the header. For instance, you can configure the parser like this:

	$parser->header_id_func = function ($text) {
	    return preg_replace('/[^a-z0-9]/', '-', strtolower($text));
	};

I'm not providing this function out of the box for a few reasons: 1. any specific algorithm to generate the id to is going to make some people complain about non-compatibility with another implementation, and 2. it's quite hard to come with something that'll work well with non-english text.

Just try it with accented characters and non-latin scripts and appreciate the nonsense. http://johnmacfarlane.net/babelmark2/?normalize=1&text=%23+English%0A%0A%23+Français%0A%0A%23+Español%0A%0A%23+čeština%0A%0A%23+Росси́я%0A%0A%23+日本%0A%0A%23+한국%0A%0A%23+العَرَبِيةُ%E2%80%8E%E2%80%8E%0A%0A%23+עברית

Honestly, I find the {#a-header} approach better.

-- 
Michel Fortin
michel.fortin at michelf.ca
https://michelf.ca

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4939 bytes
Desc: not available
URL: <https://pairlist6.pair.net/pipermail/markdown-discuss/attachments/20150709/3da77f0a/attachment.bin>


More information about the Markdown-Discuss mailing list