0

I use org-export to generate my end of week email reports. One of the links I have in those reports is for mu4e searches. I have a helper function to translate them into something more useful:

;; Exporting
(defvar my-org-mu4e-index-links
  (rx
   (: (or "query:i:" "msgid:") (group-n 1 (one-or-more any))))
  "A regex to match mu4e links of the form:

    query:i:20170228171921.21602-1-ale+qemu@clearmind.me
")

(defun my-org-mu4e-export (path desc format)
  "Format mu4e links for export."
  (when (string-match my-org-mu4e-index-links path)
    (cond
     ((eq format 'html)
      (format "<a href=\"%s%s\">%s</a>"
              "https://www.google.com/search?q="
              (match-string 1 path)
              desc))
     ((eq format 'jira)
      (format "[%s|%s%s]"
              desc
              "https://www.google.com/search?q="
              (match-string 1 path)))
     ((eq format 'ascii)
      (format "%s\nMessage-Id: <%s>" desc (match-string 1 path))))))

(use-package ox
  :config
  (org-link-set-parameters "mu4e" :export 'my-org-mu4e-export))

However what I really want is what happens with other links where the link text is surrounded by [] and the link is displayed at the bottom of the section. e.g.:

Task 1
======

  - posted message [about foo] to mailing list

[foo] Message-Id: <bar>

However I've not been able to work out where in the exporter transcoders and filters this is done. I assume I should be able to set some sort of parameter for mu4e style links to deal do this.

EDIT TO ADD

The overall export is slightly more complex as it involves parsing and filtering out lines that are no longer relevant. This is done by calling org-export-as with the following code block:

#+name: get-task-list-as-exported-text
#+begin_src emacs-lisp :exports code
  (defun my-filter-out-done-lines (s backend info)
    "Filter out lines ending in :done"
    (apply 'concat
           (--remove (s-matches? (rx ":done" (zero-or-more blank) eol) it)
                     (s-slice-at (rx bol "-") s))))

  ; headline _back-end _info
  (defun my-filter-out-old-completed-todos (s backend info)
    "Filter out DONE items if they where completed over a week ago."
    (let ((date (plist-get info :with-date))
          (todo (plist-get info :with-todo-keywords))
          (todo-type (org-element-property :todo-type s))
          (output s))
      ;; getting there
      (setq my-global-debug-var
            (add-to-list 'my-global-debug-var
                         (list :string s
                               :date date
                               :todo todo
                               :todo-type todo-type)))
      ;; strip ~~~\n lines
      (let ((start (string-match "~+\n" output)))
        (if start
            (concat (substring s 0 start)
                    (substring s (match-end 0)))
          output))))

  (org-export-define-derived-backend 'my-status-report 'ascii
    :options-alist
    '((:with-todo-keywords nil)
      (:num nil))
    :filters-alist
    '((:filter-plain-list . my-filter-out-done-lines)
      (:filter-headline . my-filter-out-old-completed-todos)))


  ;; Snarf the weeks activities
  (save-excursion
    (goto-char (point-min))
    (when (re-search-forward "* Tasks")
      (goto-char (match-beginning 0))
      (org-export-as 'my-status-report t nil t )))
#+end_src
0
1

For me an org file like

    - Read this [[mu4e:msgid:07DE09F4-70FC-4C03-B3BC-E3DE56F70FD5@andrew.cmu.edu][foo]]
    
    - a query [[query:msg:2][my description]]


exports to this ascii text


  - Read this [foo]

  - a query [my description]


[foo] <mu4e:msgid:07DE09F4-70FC-4C03-B3BC-E3DE56F70FD5@andrew.cmu.edu>

[my description] <query:msg:2>

That is not what happens in html though, neither link is shown in the summary. That section doesn't appear to be generated in the function org-html-inner-template but you could easily advise that function to add this I think. There doesn't seem to be a uniform approach to doing this for all backends.

It sort of looks like you are trying to turn the links into footnotes. You can do that in a preprocessing hook like this. I don't have a query link, so I used mu4e links here. The idea is to map over them, and replace each one with the appropriate footnote syntax, then continue with your export. Note this only works for mu4e links, and not for other kinds of links.

#+BEGIN_SRC emacs-lisp
(defun mu4e-to-footnote (_)
  (let ((mu4e-links (reverse (org-element-map (org-element-parse-buffer) 'link
                   (lambda (lnk)
                 (when (string= (org-element-property :type lnk) "mu4e")
                   lnk)))))
    (path)
    (desc))
    (cl-loop for lnk in mu4e-links
         do
         (setq path (org-element-property :path lnk)
           desc (buffer-substring (org-element-property :contents-begin lnk)
                      (org-element-property :contents-end lnk)))

         (setf (buffer-substring (org-element-property :begin lnk)
                     (org-element-property :end lnk))
           (format "%s[fn:: %s]" desc path)))))

(let ((org-export-before-processing-hook '(mu4e-to-footnote)))
  (browse-url (org-html-export-to-html)))
#+END_SRC
10
  • I am so I'm wondering where the existing logic is doing this during export so I try and hook in to that mechanism. – stsquad Jan 24 at 20:32
  • I don't think that is possible. You need something to happen at two places, where your link is, and where you want the footnotes. you would have to add a new link type like a bibliography I think, with an export for that. – John Kitchin Jan 24 at 21:15
  • But that is the existing behavior I have with other links. I certainly don't preprocess my org file with HTML links but when exported they have been split from the link location and footnotes at the end of the section. – stsquad Jan 24 at 22:55
  • what other link has that behavior? – John Kitchin Jan 25 at 0:47
  • Normal web-links are getting processed, see one of my actual updates for an example: lists.linaro.org/pipermail/linaro-toolchain/2021-January/… – stsquad Jan 25 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.