1 ;;; org-json.el --- Serve Org-mode pages as json
2 ;; suggested by nicferrier
3 ;; Copyright (C) 2014 Free Software Foundation, Inc.
6 (lexical-let ((docroot "/tmp/"))
9 (with-slots (process headers) request
10 (let ((path (ws-in-directory-p
11 docroot (substring (cdr (assoc :GET headers)) 1))))
12 (unless (and path (file-exists-p path))
13 (ws-send-404 process))
14 (save-window-excursion
16 (ws-response-header process 200
17 '("Content-type" . "application/json"))
18 (process-send-string process
19 (let ((tree (org-element-parse-buffer)))
21 (append org-element-all-objects org-element-all-elements)
23 (org-element-put-property el :parent "none")
24 (org-element-put-property el :structure "none")))
25 (json-encode tree)))))))