Skip to content

Instantly share code, notes, and snippets.

@holtzermann17
Created December 31, 2020 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holtzermann17/28c9e286ea496d896c543e4426ca0cb0 to your computer and use it in GitHub Desktop.
Save holtzermann17/28c9e286ea496d896c543e4426ca0cb0 to your computer and use it in GitHub Desktop.
First version of code for moving PARs from Org mode to XML
;;; pars.el — convert Project Action Review (in org mode) to XML
;; Copyright (c) 2020 Joseph Corneli <joseph.corneli@hyperreal.enterprises>
;;; License: AGPL 3.0
;; This program is free software: you can redistribute it and/or
;; modify it under the terms of the GNU Affero General Public License
;; as published by the Free Software Foundation, either version 3 of
;; the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see
;; <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This package converts example texts like this into XML for further
;; processing and display:
;; * Thu, 5 Mar, 17:06
;; ** Review the intention: what do we expect to learn or make together?
;; We wanted to keep learning peeragogy as part of the course
;; Wanted to work on paper
;; ** Establish what is happening: what and how are we learning?
;; We talked about the paper, our successes and failures and causal layered analysis
;; Took lots of good notes on the Google doc
;; ** What are some different perspectives on what’s happening?
;; I felt like it was a productive session!
;; ** What did we learn or change?
;; Changed the paper
;; Learned about CLA
;; ** What else should we change going forward?
;; Incorporate all the comments and ideas into the next version of the paper
;; Also some of us need to do our homework before the next class on Thursday the 12th (including me!)
;; TODO:
;; (1) Some cleanup of the syntax of exports may be needed?
;; (2) The format should be augmented with explicit Participants,
;; Date, and Project metadata.
;;; Code:
(defvar par-template "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<peeragogical-action-review title=\"%s\" xmlns=\"htx-scheme-id://org.peeragogy.20120221/patterns/peeragogical-action-review.20200511T003600Z\" xmlns:html=\"http://www.w3.org/1999/xhtml\">
<participants>%s</participants>
<intention-review>%s</intention-review>
<what-happened>%s</what-happened>
<what-happened-perspectives>%s</what-happened-perspectives>
<learnings-changes>%s</learnings-changes>
<what-else-should-change-going-forward>%s</what-else-should-change-going-forward>
</peeragogical-action-review>\n")
;; Basic spec:
;; I want to go from plain or org mode text to formatted text like the above
;; I’ll need to extract seven things from the text, which I refer to as:
;; title participants intention action view mindfulness concentration
;; I then need to produce a new archival PAR and put it somewhere.
(defun org-get-headline ()
(org-back-to-heading t)
(looking-at org-complex-heading-regexp)
(match-string-no-properties 4))
(defun org-get-body ()
(save-excursion
(save-restriction
(widen)
(let* ((elt (org-element-at-point))
(title (org-element-property :title elt))
(beg (progn (org-end-of-meta-data t) (point)))
(end (progn (outline-next-visible-heading 1) (point))))
(buffer-substring-no-properties beg end)))))
(defun org-slurp-elt ()
(org-next-visible-heading 1)
(concat "\n" (substring (org-get-body) 0 -1)))
(defun par-org-to-xml ()
(interactive)
(let* ((title (org-get-headline))
(participants (progn "TBA"))
(intention (org-slurp-elt))
(action (org-slurp-elt))
(view (org-slurp-elt))
(mindfulness (org-slurp-elt))
(concentration (org-slurp-elt)))
(save-excursion
(switch-to-buffer (get-buffer-create "*PARs*"))
(goto-char (point-max))
(insert (concat "<!-- ¶ " title "-->\n"))
(insert
(format par-template
title participants intention action view mindfulness concentration)))))
(defun parse-pars ()
(interactive)
(org-show-all)
(org-map-entries #'par-org-to-xml "LEVEL=1"))
;;; end of pars.el
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment