Skip to content

Commit 0f7c63b

Browse files
authored
Merge pull request #9 from tcahill/org-9.7-support
Handle changes to org AST in v9.7
2 parents 2803943 + 2bcc833 commit 0f7c63b

4 files changed

Lines changed: 61 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- 27-2
1717
- 28-2
1818
- 29-1
19+
- snapshot
1920
allow-failure: [false]
2021
include:
2122
- emacs-version: 26-3
@@ -35,5 +36,5 @@ jobs:
3536
- name: Build and test
3637
run: |
3738
echo org-version = $(make org-version)
38-
make byte-compile
39+
make byte-compile-strict
3940
make run-tests

Makefile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ TESTS_EVAL="(ert-run-tests-batch-and-exit '(and \"$(TESTS_REGEXP)\" (not (tag :i
3838

3939
EMACS_LIBS=-L $(WORK_DIR) -L $(WORK_DIR)/$(TEST_DIR) $(shell for dep in $(TEST_DEPS); do echo -l $$dep; done)
4040

41-
# Value of byte-compile-warnings elisp variable
42-
BYTE_COMPILE_WARNINGS='(not docstrings obsolete)
41+
# Value of byte-compile-warnings elisp variable in byte-compile-strict rule
42+
BYTE_COMPILE_WARNINGS='(not docstrings obsolete suspicious)
4343

4444

45-
.PHONY : install-deps byte-compile test run-tests test-interactive clean emacs test-deps org-version lint export-test-org
45+
.PHONY : install-deps byte-compile byte-compile-strict test run-tests test-interactive clean emacs test-deps org-version lint export-test-org
4646

4747

4848
# Install package and test dependencies
@@ -52,14 +52,21 @@ BYTE_COMPILE_WARNINGS='(not docstrings obsolete)
5252
# Alias for previous (unless SKIP_INSTALL_DEPS)
5353
install-deps : $(if $(NO_INSTALL_DEPS),,.emacs.d/elpa)
5454

55-
# Byte-compile elisp files
56-
byte-compile : install-deps
57-
@$(EMACS_BATCH) $(EMACS_PKG) \
55+
# Byte-compile elisp files, throwing error on warnings
56+
byte-compile-strict : install-deps
57+
$(EMACS_BATCH) $(EMACS_PKG) \
5858
--eval "(setq byte-compile-error-on-warn t)" \
5959
--eval "(setq byte-compile-warnings $(BYTE_COMPILE_WARNINGS))" \
6060
--eval "(batch-byte-compile)" \
6161
*.el
6262

63+
# Byte-compile elisp files
64+
byte-compile : install-deps
65+
$(EMACS_BATCH) $(EMACS_PKG) \
66+
--eval "(setq byte-compile-warnings t)" \
67+
--eval "(batch-byte-compile)" \
68+
*.el
69+
6370
# Check that test dependences can be loaded
6471
test-deps :
6572
@for dep in $(TEST_DEPS); do \

ox-json.el

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
;; using `ox-json-encode-auto'.
6363

6464
;; :json-postprocess (symbol) - How to postprocess the final output. Values are `pretty'
65-
; (indent properly), `minimal' (remove whitespace), and nil (nothing, maybe faster?).
65+
;; (indent properly), `minimal' (remove whitespace), and nil (nothing, maybe faster?).
6666

6767
;;; Code:
6868

@@ -106,6 +106,7 @@ be overridden with the :json-exporters option.")
106106
all (
107107
; Never include parent, leads to infinite recursion
108108
:parent nil
109+
:buffer nil
109110
; These properties have to do with absolute buffer positions and thus probably aren't useful to export
110111
:begin nil
111112
:end nil
@@ -356,9 +357,29 @@ Used for error reporting.")
356357
;;; Org-mode utility code
357358

358359
(defun ox-json-node-properties (node)
359-
"Get property plist of element/object NODE."
360-
; It's the 2nd element of the list
361-
(cadr node))
360+
"Org v9.7 introduced two significant changes to the AST that must be
361+
considered when enumerating a node's properties:
362+
363+
1. Some properties which were previously present in the property
364+
list (e.g. :begin and :end) are now stored as elements of a vector
365+
under the :standard-properties key in the property list.
366+
367+
2. Property values can now be 'deferred', meaning they are not
368+
calculated until accessed via a getter function like
369+
~org-element-property~.
370+
371+
~org-element-properties-map~ is now the recommended way to traverse a
372+
node's properties and handles both of these changes."
373+
(if (fboundp 'org-element-properties-map)
374+
(let ((expanded-properties nil))
375+
(org-element-properties-map
376+
(lambda (name value)
377+
(setq expanded-properties (plist-put expanded-properties name value)))
378+
node t)
379+
expanded-properties)
380+
; for org versions < 9.7, just return the property list, which is the second
381+
; element of the list
382+
(cadr node)))
362383

363384
(defun ox-json--is-node (value)
364385
"Check if VALUE is an org element/object."
@@ -945,6 +966,12 @@ JSON-encoded values."
945966
info
946967
type-plists)))
947968

969+
(defun ox-json--skip-property (property)
970+
"Return non-nil if an element property PROPERTY should be skipped, regardless of the value of the
971+
:json-property-types option."
972+
; Apparently 9.7 introduces some private property names, skip these.
973+
(cl-search "--" (symbol-name property)))
974+
948975
(defun ox-json--export-properties-base (property-plist default-type info &rest type-plists)
949976
"Export org node property values by looking up their types in a series of plists.
950977
@@ -962,7 +989,7 @@ JSON-encoded values."
962989
(ox-json--loop-plist (key value property-plist)
963990
do (setq property-type
964991
(apply #'ox-json--plists-get-default key default-type type-plists))
965-
if property-type
992+
if (and property-type (not (ox-json--skip-property key)))
966993
collect (cons key (ox-json-encode-with-type property-type value info)))))
967994

968995
(cl-defun ox-json-export-node-base
@@ -1162,7 +1189,7 @@ INFO is the plist of export options."
11621189
:extra-properties (ox-json-timestamp-extra-properties timestamp info))))
11631190

11641191

1165-
;;; Filter functions functions
1192+
;;; Filter functions
11661193

11671194
(defun ox-json-filter-final-output (text back-end info)
11681195
"Post-process the entire output."

tests/test-export.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
("mode" . t)
2323
; Seems to have a different value in 9.6 vs others?
2424
("post-blank" . t)
25+
; Added in org 9.7
26+
; Not sure if all are useful, some should probably be excluded from export
27+
("cached" . t)
28+
("deferred" . t)
29+
("raw-value" . t)
30+
("structure" . t)
31+
("secondary" . t)
32+
("true-level" . t)
33+
; And these seem to have a different value in 9.7...
34+
("archivedp" . t)
35+
("footnote-section-p" . t)
36+
("type-explicit-p" . t)
37+
("range-type" . t)
2538
)
2639
)
2740
)

0 commit comments

Comments
 (0)