From 45adf4aac247f5a730f4cc430d84c65e9758d5e7 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Mon, 6 Dec 2021 02:19:23 +0800 Subject: [PATCH] Create anchor for headings --- _includes/refactor-content.html | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/_includes/refactor-content.html b/_includes/refactor-content.html index 7e899ff..ea6ceed 100644 --- a/_includes/refactor-content.html +++ b/_includes/refactor-content.html @@ -147,6 +147,43 @@ {% endif %} + + +{% assign heading_levels = '2,3,4,5' | split: ',' %} +{% assign _heading_content = _content %} + +{% for level in heading_levels %} + {% capture mark_start %}{% endcapture %} + + {% assign left = snippet | split: mark_end | first %} + {% assign right = snippet | replace: left, '' %} + + {% assign _new_content = _new_content | append: mark_start + | append: left | append: anchor | append: mark_end | append: right + %} + + {% endfor %} + + {% assign _heading_content = _new_content %} + + {% endif %} +{% endfor %} + +{% assign _content = _heading_content %}