RENDER HOOKS

Introduction

在將 Markdown 渲染為 HTML 時,渲染 Hook 可以覆蓋轉換行為。每個渲染 Hook 都是一個模板,每種支援的元素類型對應一個模板:

例如,以下是 Markdown 範例:

[Hugo](https://gohugo.io)

![kitten](kitten.jpg)

如果沒有連結或圖片的渲染 Hook,上述範例會被渲染為:

<p><a href="https://gohugo.io">Hugo</a></p>
<p><img alt="kitten" src="kitten.jpg"></p>

透過創建連結與圖片的渲染 Hook,可以改變從 Markdown 到 HTML 的轉換。例如:

<p><a href="https://gohugo.io" rel="external">Hugo</a></p>
<p><img alt="kitten" src="kitten.jpg" width="600" height="400"></p>

每個渲染 Hook 都是一個模板,並對應每種支援的元素類型:

layouts/
└── _default/
    └── _markup/
        ├── render-blockquote.html
        ├── render-codeblock.html
        ├── render-heading.html
        ├── render-image.html
        ├── render-link.html
        ├── render-passthrough.html
        └── render-table.html

模板的查找順序允許您為每個頁面 類型種類、語言及 輸出格式 創建不同的渲染 Hook。例如:

layouts/
├── _default/
│   └── _markup/
│       ├── render-link.html
│       └── render-link.rss.xml
├── books/
│   └── _markup/
│       ├── render-link.html
│       └── render-link.rss.xml
└── films/
    └── _markup/
        ├── render-link.html
        └── render-link.rss.xml

本章節的其餘頁面將描述每種類型的渲染 Hook,包括範例和每個模板所接收的上下文。