Internal links in rmarkdown don't work

前端 未结 5 952
夕颜
夕颜 2020-12-14 16:13

I use rmarkdown to render pdf documents. Now I want to add internal links in the texts.

In the helping pages of rmarkdown, it says an internal link is defined as:

5条回答
  •  盖世英雄少女心
    2020-12-14 16:59

    @rPirate has a good list, but it was missing a case that was befuddling me. I had a section header like ### 1.1.1 My Section Title that needs to be #my-section-title in the link.

    After some searching, I found an official list of transformation rules in the Pandoc manual:

    The default algorithm used to derive the identifier from the header text is:

    • Remove all formatting, links, etc.
    • Remove all footnotes.
    • Remove all non-alphanumeric characters, except underscores, hyphens, and periods.
    • Replace all spaces and newlines with hyphens.
    • Convert all alphabetic characters to lowercase.
    • Remove everything up to the first letter (identifiers may not begin with a number or punctuation mark).
    • If nothing is left after this, use the identifier section.

    Thus, for example,

    Header                      | Identifier
    --------------------------------------------------------
    Header identifiers in HTML  | header-identifiers-in-html
    Maître d'hôtel              | maître-dhôtel
    *Dogs*?--in *my* house?     | dogs--in-my-house
    [HTML], [S5], or [RTF]?     | html-s5-or-rtf
    3. Applications             | applications
    33                          | section
    

提交回复
热议问题