use heading render hook instead of refactor
This commit is contained in:
		
							
								
								
									
										8
									
								
								layouts/_default/_markup/render-heading.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								layouts/_default/_markup/render-heading.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| <h{{ .Level }} id="{{ .Anchor }}" {{- range $key, $value := .Attributes }} {{- printf " %s=%v" $key $value | safeHTMLAttr }}{{- end }}> | ||||
|   {{ if and (ne .Level 1) (not (index .Attributes "data-toc-skip")) }} | ||||
|     <span class="me-2">{{- .Text -}}</span> | ||||
|     <a href="#{{ .Anchor }}" class="anchor text-muted"><i class="fas fa-hashtag"></i></a> | ||||
|   {{ else }} | ||||
|     {{- .Text -}} | ||||
|   {{ end }} | ||||
| </h{{ .Level }}> | ||||
| @@ -18,19 +18,4 @@ | ||||
|   {{ $content = replaceRE `<input.*?type="checkbox".*?>` `<i class="far fa-circle fa-fw"></i>` $content }} | ||||
| {{ end }} | ||||
|  | ||||
| <!-- Create heading anchors --> | ||||
| {{ $headingLevels := slice "2" "3" "4" "5" }} | ||||
| {{ $headingContent := $content }} | ||||
|  | ||||
| {{ range $level := $headingLevels }} | ||||
|   {{ $markStart := printf `<h%s id="` $level }} | ||||
|   {{ $markEnd := printf `</h%s>` $level }} | ||||
|    | ||||
|   {{ $pattern := printf `%s([^"]+)">(.*?)%s` $markStart $markEnd }} | ||||
|   {{ $replacement := printf `%s$1"><span class="me-2">$2</span><a href="#$1" class="anchor text-muted"><i class="fas fa-hashtag"></i></a>%s` $markStart $markEnd }} | ||||
|   {{ $headingContent = replaceRE $pattern $replacement $headingContent }} | ||||
| {{ end }} | ||||
|  | ||||
| {{ $content = $headingContent | safeHTML }} | ||||
|  | ||||
| {{ $content | safeHTML }} | ||||
		Reference in New Issue
	
	Block a user
	 geekifan
					geekifan