【问题标题】:Jekyll Markup like HTML href="#myElementId"? [duplicate]像 HTML href="#myElementId" 这样的 Jekyll 标记? [复制]
【发布时间】:2016-12-26 00:35:23
【问题描述】:

有没有办法在博客文章中创建锚点并链接到它们,就像使用 html hrefs 到元素一样?

我基本上想要一个在长博文顶部带有链接的目录。

已经有一个问题,似乎没有没有插头的实际答案,想要确认:How to create a table of contents to Jekyll blog post?

【问题讨论】:

    标签: html markdown jekyll


    【解决方案1】:

    有没有办法在博客文章中创建锚点并链接到它们,就像使用 html hrefs 到元素一样?

    是的,对元素使用 html href。以下html代码:

    <hr>
    
    <h1>Table of contents:</h1>
    
    <ul>
      <li><a href="#goto-1">Chapter 1</a><a id="toc-1"></a></li>
      <li><a href="#goto-2">Chapter 2</a><a id="toc-2"></a></li>
    </ul>
    
    <hr>
    
    <a id="goto-1"></a>
    <h1><a href="#toc-1">↑</a> Chapter 1</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    
    <a id="goto-2"></a>
    <h1><a href="#toc-2">↑</a> Chapter 2</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

    可以在帖子中使用以下标记生成:

    ---
    
    **Table of contents:**
    
    * [Chapter 1](#goto-1)<a id="toc-1"></a>
    * [Chapter 2](#goto-2)<a id="toc-2"></a>
    
    ---
    
    <a id="goto-1"></a>**[↑](#toc-1) Chapter 1**
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    
    <a id="goto-2"></a>**[↑](#toc-2) Chapter 2**
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    

    【讨论】:

      猜你喜欢
      • 2018-05-14
      • 1970-01-01
      • 2020-05-12
      • 2013-02-27
      • 1970-01-01
      • 2013-02-12
      • 1970-01-01
      • 2013-05-19
      相关资源
      最近更新 更多