🎉 Feat: support Obsidian style task lists

This commit is contained in:
Cell
2024-10-31 17:10:59 +08:00
parent 8d10880b35
commit 867984fda2
3 changed files with 39 additions and 10 deletions
-9
View File
@@ -1,9 +0,0 @@
{{- /* Checkbox unchecked */ -}}
{{- $old := `<input disabled="" type="checkbox">` -}}
{{- $new := dict "Class" "fa-regular fa-square fa-fw" | partial "plugin/icon.html" -}}
{{- $content := replace . $old $new -}}
{{- /* Checkbox checked */ -}}
{{- $old = `<input checked="" disabled="" type="checkbox">` -}}
{{- $new := dict "Class" "fa-regular fa-check-square fa-fw" | partial "plugin/icon.html" -}}
{{- return replace $content $old $new -}}
+1 -1
View File
@@ -14,7 +14,7 @@
{{- $content = partial "function/fontawesome.html" $content -}}
{{- end -}}
{{- $content = partial "function/checkbox.html" $content -}}
{{- $content = partial "function/task-lists.html" $content -}}
{{- $content = partial "function/escape.html" $content -}}
+38
View File
@@ -0,0 +1,38 @@
{{- /* Task lists rendering */ -}}
{{- /* If Hugo supports the list rendering hook, refactor this snippet. */ -}}
{{- $iconMap := dict
" " "fa-regular fa-square"
"x" "fa-solid fa-check-square"
">" "fa-solid fa-calendar"
"<" "fa-solid fa-calendar-check"
-}}
{{- $extendedSigns := slice -}}
{{- range $sign, $icon := $iconMap -}}
{{- $extendedSigns = $extendedSigns | append $sign -}}
{{- end -}}
{{- /*
The basic syntax is compatible with GitHub, Obsidian, and Typora.
The basic format is as follows:
- [ ] Unchecked
- [x] Checked
*/ -}}
{{- $icon := dict "Class" (add "checkbox-icon fa-fw " (index $iconMap " ")) | partial "plugin/icon.html" -}}
{{- $content := replaceRE `<li><input disabled="" type="checkbox"> (.+?)</li>` (printf `<li data-task=" ">%s $1</li>` $icon) . -}}
{{- $icon := dict "Class" (add "checkbox-icon fa-fw " (index $iconMap "x")) | partial "plugin/icon.html" -}}
{{- $content = replaceRE `<li><input checked="" disabled="" type="checkbox"> (.+?)</li>` (printf `<li data-task="x">%s $1</li>` $icon) $content -}}
{{- /*
The extended syntax is compatible with Obsidian.
The extended format is as follows:
- [>] Scheduled
- [<] Rescheduled
*/ -}}
{{- range $extendedSigns -}}
{{- $class := index $iconMap . | default "fa-solid fa-check-square" -}}
{{- $icon := dict "Class" (add "checkbox-icon fa-fw " $class) | partial "plugin/icon.html" -}}
{{- $content = replaceRE (printf `<li>\[%s\] (.+?)</li>` (htmlEscape .)) (printf `<li data-task="%s">%s $1</li>` . $icon) $content -}}
{{- end -}}
{{- return $content -}}