9

I might be missing something really obvious (or might have developed temporary blindness staring at the Haddock user guide), but I can't seem to find any way to link to a named chunk of documentation in Haddocks

Edit: I'm trying to create an internal hyperlink from one part of the doc to another named chunk of documentation. I've tried the following:

-- You may want to take a look at 'findByPkHelpers' section for
-- variations of this function.
--
-- I even tried putting '$findByPkHelpers' but didn't work
--
-- ... snip ...

-- ** Some heading
-- 
-- $findByPkHelpers
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
  • What have you tried that isn't working? Is putting `-- $somechunkname` in the export list not enough? – danidiaz Jul 28 '18 at 14:05
  • Have added clarifications to the question. – Saurabh Nanda Jul 28 '18 at 14:47
  • Can you give a full reprodicible example? – sjakobi Jul 29 '18 at 12:08
  • Oh, and named chunks are not for linking. AFAIK a reference to a named chunk is simply replaced by the contents of the named chunk. – sjakobi Jul 29 '18 at 12:10
  • For linking you can try anchors: http://haskell-haddock.readthedocs.io/en/latest/markup.html#anchors – sjakobi Jul 29 '18 at 12:11
  • Hang on, are anchors and named-chunks completely different concepts? I've spent an hour trying to link to a named chunk using the `#something` syntax, but it just doesn't work. – Saurabh Nanda Jul 29 '18 at 14:26
  • @SaurabhNanda: Yeah, anchors and named chunks are unrelated. – sjakobi Jul 30 '18 at 12:24
  • @sjakobi there isn't any reason why **both** of these should exist, right? It should be possible to link directly to named chunks of documentation, right? – Saurabh Nanda Aug 01 '18 at 07:44
  • @SaurabhNanda: In my understanding, named chunks are about reducing clutter in export lists. So they do have a different purpose than anchors. You should still be able to make a link to a named chunk by including an anchor label in the named chunk. – sjakobi Aug 02 '18 at 00:26

1 Answers1

2

You can use the syntax #myanchor to create an anchor, and then you can link to it with [my link text](#myanchor). For example, in my export list I have

    -- | #launchaprocess#

    -- * Launch a process
    , runProcess
    , readProcess

and then in the body of the file I have a link to this anchor

-- | Once you have a @ProcessConfig@ you can launch a process from it
-- using the functions in the section [Launch a process](#launchaprocess).

(N.B. in the case of anchors next to section headers in export lists there must be a blank link between them otherwise the * introducing the header will be interpreted as a Haddock-comment bulleted list!)

[Thanks to @sjakobi for pointing out this functionality]

Tom Ellis
  • 9,224
  • 1
  • 29
  • 54