I've figured out something that works but isn't perfect.
#+NAME: html-image-size
#+BEGIN_SRC emacs-lisp :var text="" :var width="100%" :var height="100%" :results raw
(concat "#+ATTR_HTML: :width " width " :height " height "\n[[file:" text "]]")
#+END_SRC
Then I can set the :results
of a src block to raw
and add that emacs-lisp src block as a :post
header arg.
#+BEGIN_SRC python :noweb-ref test-detect-table :noweb yes :results raw :post html-image-size(text=*this*, width="300px")
import cv2
<<detect-table>>
image_filename = "resources/examples/example-page.png"
image = cv2.imread(image_filename, cv2.IMREAD_GRAYSCALE)
image = find_tables(image)[0]
cv2.imwrite("resources/examples/example-table.png", image)
"resources/examples/example-table.png"
#+END_SRC
That is almost perfect. The only thing I've noticed that I lose is org-babel-remove-result
no longer works. It just removes the #+RESULTS:
line while the file link remains.
Anyone know of a solution to that?
Edit: Found a solution.
There's no configurable option. There is a defconst
regex that org-babel uses to find the start/end of result blocks. But I wrote a function to remove the #+ATTR.*
lines that were causing the built-in regex to fail.
(defun remove-attributes-from-src-block-result (&rest args)
(let ((location (org-babel-where-is-src-block-result))
(attr-regexp "[ ]*#\\+ATTR.*$"))
(when location
(save-excursion
(goto-char location)
(when (looking-at (concat org-babel-result-regexp ".*$"))
(next-line)
(while (looking-at attr-regexp)
(kill-whole-line)))))))
(advice-add 'org-babel-remove-result :before #'remove-attributes-from-src-block-result)
(advice-add 'org-babel-execute-src-block :before #'remove-attributes-from-src-block-result)