Thanks @xeijin for this idea! Ref: https://github.com/kaushalmodi/ox-hugo/issues/272master
parent
5be9bae6fe
commit
f8b6ab2619
5 changed files with 113 additions and 0 deletions
@ -0,0 +1,47 @@ |
||||
(defun xeijin/conv-chkbox-items-to-front-matter (hl) |
||||
"Find the headline exactly matching HL. |
||||
|
||||
Then find all plain list items under HL and return as a |
||||
list \\='((checked . (VALa VALb ..)) (not-checked . (VALx VALy |
||||
..))). |
||||
|
||||
- The values in \"checked\" cons are the Org list items with |
||||
checkbox in \"on\" state. |
||||
|
||||
- The value in \"not-checked\" cons are the Org list items with |
||||
any other checkbox state, or no checkbox." |
||||
;; (message "dbg x: pt: %d" (point)) |
||||
(let (hl-as-element |
||||
checked not-checked |
||||
ret) |
||||
(save-restriction |
||||
(ignore-errors |
||||
(org-narrow-to-subtree)) ;This will give error when there's no |
||||
;heading above the point, which will |
||||
;be the case for per-file post flow. |
||||
(save-excursion |
||||
(goto-char (point-min)) |
||||
;; (message "dbg y: pt: %d" (point)) |
||||
(let (case-fold-search) ;Extracted from `org-find-exact-headline-in-buffer' |
||||
(re-search-forward |
||||
(format org-complex-heading-regexp-format (regexp-quote hl)) nil :noerror)) |
||||
;; (message "dbg z: pt: %d" (point)) |
||||
(save-restriction |
||||
(org-narrow-to-subtree) ;Narrow to the `hl' headline |
||||
(setq hl-as-element (org-element-parse-buffer))) |
||||
;; (message "dbg: %S" hl-as-element) |
||||
(org-element-map hl-as-element 'item ;Map over headline's items |
||||
(lambda (item) |
||||
(let* ((checkbox-state (org-element-property :checkbox item)) ;Get checkbox value of item |
||||
(item-text (string-trim (substring-no-properties |
||||
(org-element-interpret-data |
||||
(org-element-contents item)))))) |
||||
(cond |
||||
((eq checkbox-state 'on) |
||||
(push item-text checked)) |
||||
(t ;checkbox state in `off' or `trans' state, or if no checkbox present |
||||
(push item-text not-checked)))))) |
||||
(setq ret `((checked . ,(nreverse checked)) |
||||
(not-checked . ,(nreverse not-checked)))))) |
||||
;; (message "dbg: ret: %S" ret) |
||||
ret)) |
||||
@ -0,0 +1,16 @@ |
||||
+++ |
||||
title = "Meeting 1" |
||||
author = ["xeijin"] |
||||
tags = ["custom-fm", "elisp"] |
||||
draft = false |
||||
[attendees] |
||||
checked = ["Attendee 1"] |
||||
not-checked = ["Attendee 2", "Attendee 3", "Attendee 4"] |
||||
+++ |
||||
|
||||
`ox-hugo` Issue #[272](https://github.com/kaushalmodi/ox-hugo/issues/272) |
||||
|
||||
|
||||
## Notes {#notes} |
||||
|
||||
My notes |
||||
@ -0,0 +1,16 @@ |
||||
+++ |
||||
title = "Meeting 2" |
||||
author = ["xeijin"] |
||||
tags = ["custom-fm", "elisp"] |
||||
draft = false |
||||
[attendees] |
||||
checked = ["Attendee x", "Attendee z"] |
||||
not-checked = ["Attendee y", "Attendee w"] |
||||
+++ |
||||
|
||||
`ox-hugo` Issue #[272](https://github.com/kaushalmodi/ox-hugo/issues/272) |
||||
|
||||
|
||||
## Notes {#notes} |
||||
|
||||
My notes |
||||
Loading…
Reference in new issue