Automatically create a reference link for headers when auto_ids=true

28 views
Skip to first unread message

Luc Bourhis

unread,
Aug 12, 2016, 5:21:44 PM8/12/16
to kramdown-users
With auto_ids=true, the following kramdown

    # My header

generates the following HTML

    <h1 id="my-header">My header</h1>

So far so good. But in order to refer to it in the text elsewhere, one needs to type

   See [My header](#my-header) for enlightenment 

It would be nice if kramdown automatically created a link definition

    [My header]: #my-header

so that one could then refer to it with the much better looking reference link

    See [My header] for enlightenment

But I can't find any way to do that. Am I missing something? Pandoc has that feature for the record.


Thomas Leitner

unread,
Aug 16, 2016, 5:10:56 AM8/16/16
to kramdow...@googlegroups.com
On 2016-08-12 14:21 -0700 Luc Bourhis wrote:
> So far so good. But in order to refer to it in the text elsewhere,
> one needs to type
>
> See [My header](#my-header) for enlightenment
>
> It would be nice if kramdown automatically created a link definition
>
> [My header]: #my-header

kramdown currently doesn't have such a feature. One reason why this may
be a bit difficult to implement is that the automatic IDs are only
created when converting the internal representation to HTML, not when
parsing. But inline reference links are created during the parsing
phase because we need to know whether `[My header]` is a reference link
or just text.

What is already possible is using the option "link_defs" for providing
link definitions. This is used, for example, in the static website
generator webgen to allow automatic linking to headers.

Best regards,
Thomas
Reply all
Reply to author
Forward
0 new messages