How to link to part of the same document in Markdown?

前端 未结 14 1712
眼角桃花
眼角桃花 2020-11-29 14:50

I am writing a large Markdown document and would like to place a table of contents of sorts at the beginning that will provide links to various locations in the document. Ho

14条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 15:25

    In pandoc, if you use the option --toc in producing html, a table of contents will be produced with links to the sections, and back to the table of contents from the section headings. It is similar with the other formats pandoc writes, like LaTeX, rtf, rst, etc. So with the command

    pandoc --toc happiness.txt -o happiness.html
    

    this bit of markdown:

    % True Happiness
    
    Introduction
    ------------
    
    Many have posed the question of true happiness.  In this blog post we propose to
    solve it.
    
    First Attempts
    --------------
    
    The earliest attempts at attaining true happiness of course aimed at pleasure. 
    Soon, though, the downside of pleasure was revealed.
    

    will yield this as the body of the html:

    True Happiness

    Introduction

    Many have posed the question of true happiness. In this blog post we propose to solve it.

    First Attempts

    The earliest attempts at attaining true happiness of course aimed at pleasure. Soon, though, the downside of pleasure was revealed.

提交回复
热议问题