Comments (6)
I agree that it'd be great to be able to use heading as "front" and content under the heading as "back".
I have a lot of .org files that I can't use in either anki-editor or org-drill because they require structural changes :/
from anki-editor.
Yesterday I have played around a bit:
(setq anki-editor-quick-field-mapping '(("Basic" . ("Front" . nil))))
(defun anki-editor-get-quick-fields ()
""
(interactive)
(let* (quick-fields
(note-heading (org-element-at-point))
(note-title (org-element-property :title note-heading))
(note-type (org-element-property :ANKI_NOTE_TYPE note-heading))
(quick-field-mapping (alist-get note-type anki-editor-quick-field-mapping 'equal))
(title-field (car quick-field-mapping))
(contents-field (cdr quick-field-mapping))
(contents-begin (org-element-property :contents-begin note-heading))
(contents-end (org-element-property :contents-end note-heading))
(point-of-first-child (- (save-excursion
(if (org-goto-first-child)
(point)
(point-max)))
1)))
(when title-field
(map-put quick-fields
title-field
(org-export-string-as note-title
anki-editor--ox-anki-html-backend
t
anki-editor--ox-export-ext-plist)
'equal))
(when contents-field
(map-put quick-fields
contents-field
(cond
((and contents-begin contents-end)
(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 point-of-first-child))
anki-editor--ox-anki-html-backend
t
anki-editor--ox-export-ext-plist))
(t ""))
'equal))
quick-fields))
(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."
(save-excursion
(let ((fields (anki-editor-get-quick-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'
(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)))
(map-put fields
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 ""))
'equal)
(org-forward-heading-same-level nil t))))
(reverse fields))))
I tried to allow the contents of the heading to be associated with the Back
field via:
(setq anki-editor-quick-field-mapping '(("Basic" . ("Front" . "Back"))))
But I do not know yet, how to export the contents of the heading without the properties drawer. Maybe you have an idea.
Maybe you have some hints. I will create a pull request after I played around a bit.
Edit: Nice! I found that
(setq anki-editor--ox-export-ext-plist '(:with-toc nil :anki-editor-mode t :with-drawers nil))
Hides the drawers correctly. I will prepare a pull request as soon as I can.
from anki-editor.
Yes please! I would also use something like this.
from anki-editor.
Sorry for the delay. I was focusing on my personal stuff last few months.
I would say this is really a good idea. I always find it's tricky to come up with a name for every note and sometimes I have to write the same content in heading and front field, so I was also thinking about a solution to this.
Your experimentation looks good, but it requires configuration for mapping between fields and note types. An alternative I prefer is just comparing the number of expected fields with the actual number of subtrees under the note to find out the missing field and use note heading as that field. I have implemented the idea in the develop branch, go check it out to see if that works for you.
from anki-editor.
Thanks @louietan
This means that I would still have to keep a Back
heading for each card?
How would anki-editor know which is Front
and which is Back
?
I think your solution is okay for cards with more than two fields, because then we can check the missing field name. For two fields we still need configurability, no?
My solution allows to write:
* My question for the Front field
My content for the Back field
from anki-editor.
Why not just:
* Front
Back
from anki-editor.
Related Issues (20)
- Match org headings escaped with a `,` (needed within org source blocks) HOT 1
- Status of this package and a way ahead HOT 15
- Pushing cloze fails with unknown reason HOT 10
- Is there a recommended workflow for deleting a card (or set of cards)? HOT 2
- Is anyone still developing this project? I find it very useful HOT 2
- ANKI_NOTE_ID not updated after push HOT 1
- Provide a keymap for the anki-editor-mode HOT 1
- Custom faces for Anki's cloze syntax HOT 1
- Question: Does the sync work in both directions? HOT 1
- Number Cloze deletions with consecutive IDs automatically HOT 1
- Can't push notes on WSL2 HOT 2
- Wrong type argument: integer-or-marker-p, nil (develop branch) HOT 2
- Any way to avoid "cannot create note because it is a duplicate"? HOT 1
- AnkiDroid doesn't support wrapping each lines of display equations in <div>
- pushing tree broke HOT 2
- anki-editor-push-notes creates "two" cards HOT 1
- Superscript issues HOT 2
- Add syntax highlighting to src blocks HOT 9
- Per file properties do not work HOT 1
- SRC block exported even if :exports results is set HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anki-editor.