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

Match org headings escaped with a , (needed within org source blocks) #100

Open
tommyphillips opened this issue Jun 28, 2022 · 1 comment

Comments

@tommyphillips
Copy link

tommyphillips commented Jun 28, 2022

In an org file, I would like to 'hide' anki-editor code as much as possible.
My strategy for doing so is to write the anki-editor within a source block as follows:

#+begin_src org
,*  Question Name
:PROPERTIES:
:ANKI_NOTE_TYPE: Cloze
:ANKI_DECK: Programming
:ANKI_NOTE_ID: 1653402332712
:END:

,** Text

{{c1::Solution::Question}}

#+end_src

The problem is that it is necessary to escape the heading *s using ,*
Otherwise, the main org document will interpret headings within the block as part of the main document.
But anki-editor does not recognise this ,* syntax.
I have had a look at the source code, but I am no expert.
It seems that probably only a small tweak is required to enable anki-editor to recognise the ,*.

If anyone could help, I would appreciate it.
In case anyone suggests tangling the block to another file, and then pushing that file to anki, this is not the ideal solution, because the source block will not receive the ANKI_NOTE_ID.

@tommyphillips
Copy link
Author

Workaround found: I have put this in my .emacs and it enables me to push the notes to anki while keeping the ,* sytax:

(defun tap/push-escaped-source-block-to-anki ()
  (interactive)

  (defun tap/select-source-block ()
    (search-backward "#\+begin_src")
    (next-line)
    (set-mark-command nil)
    (search-forward "#\+end_src")
    (previous-line)
    (end-of-line)
    )
  (anki-editor-mode 1)
  (tap/select-source-block)
  (let ((p1 (region-beginning))
	(p2 (region-end)))
    (save-restriction (narrow-to-region p1 p2)
		      (goto-char (point-min))
		      (while (re-search-forward "^," nil t) (replace-match "" nil t))
		      (anki-editor-push-notes)
		      (goto-char (point-min))
		      (while (re-search-forward "^\*" nil t) (replace-match ",\*" nil t))
		      )))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant