Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support referencing any contents in the org fileYork #102

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*~*
45 changes: 22 additions & 23 deletions anki-editor.el
Original file line number Diff line number Diff line change
Expand Up @@ -549,42 +549,41 @@ Where the subtree is created depends on PREFIX."
(values (and value (split-string value))))
(mapcar #'org-entry-restore-space values)))

(defun anki-editor--export-subtree ()
(let ((org-export-show-temporary-export-buffer nil)
(outbuf "*anki-editor-export*"))
(org-export-to-buffer
anki-editor--ox-anki-html-backend
outbuf nil t nil t
anki-editor--ox-export-ext-plist)
(with-current-buffer outbuf
(buffer-substring-no-properties (point-min) (point-max)))))

(defun anki-editor--build-fields ()
"Build a list of fields from subheadings of current heading, each element of which is a cons cell, the car of which is field name and the cdr of which is field content."
"Build a list of fields from subheadings of current heading, each
element of which is a cons cell, the car of which is field name
and the cdr of which is field content."
(save-excursion
(let (fields
(point-of-last-child (point)))
(when (org-goto-first-child)
(while (/= point-of-last-child (point))
(setq point-of-last-child (point))
(let* ((inhibit-message t) ;; suppress echo message from `org-babel-exp-src-block'
(let* ((inhibit-message t) ;; suppress echo message from
;; `org-babel-exp-src-block'
(field-heading (org-element-at-point))
(field-name (substring-no-properties
(org-element-property
:raw-value
field-heading)))
(contents-begin (org-element-property :contents-begin field-heading))
(contents-end (org-element-property :contents-end field-heading)))
field-heading))))

(push (cons field-name
(cond
((and contents-begin contents-end) (or (org-export-string-as
(buffer-substring
contents-begin
;; in case the buffer is narrowed,
;; e.g. by `org-map-entries' when
;; scope is `tree'
(min (point-max) contents-end))
anki-editor--ox-anki-html-backend
t
anki-editor--ox-export-ext-plist)

;; 8.2.10 version of
;; `org-export-filter-apply-functions'
;; returns nil for an input of empty string,
;; which will cause AnkiConnect to fail
""))
(t "")))
(or (anki-editor--export-subtree)
;; 8.2.10 version of
;; `org-export-filter-apply-functions'
;; returns nil for an input of empty string,
;; which will cause AnkiConnect to fail
""))
fields)
(org-forward-heading-same-level nil t))))
(reverse fields))))
Expand Down