At this point, the plugin loads, but it couldn’t find the exported src blocks. As I mentioned above, I was unable to find a satisfactory solution using export filters, so in the end I just rewrote the function
org-reveal-src-block, which ox-reveal uses to process src blocks. I decided to keep the original
<pre><code> syntax and simply add on an additional
<klipse-snippet block, using the
display:none CSS property for the old code block. This ensures compatibility with the reveal-editor solution (which isn’t currently working for me, but offers some other features.
Here’s my modified function:
(defun org-reveal-src-block (src-block contents info)
"Transcode a SRC-BLOCK element from Org to Reveal.
CONTENTS holds the contents of the item. INFO is a plist holding
(if (org-export-read-attribute :attr_html src-block :textarea)
(let* ((use-highlight (org-reveal--using-highlight.js info))
(lang (org-element-property :language src-block))
(caption (org-export-get-caption src-block))
(code (if (not use-highlight)
(org-html-format-code src-block info)
(cl-letf (((symbol-function 'org-html-htmlize-region-for-paste)
(org-html-format-code src-block info))))
(frag (org-export-read-attribute :attr_reveal src-block :frag))
(code-attribs (or (org-export-read-attribute
:attr_reveal src-block :code_attribs) ""))
(label (let ((lbl (org-element-property :name src-block)))
(if (not lbl) ""
(format " id=\"%s\"" lbl))))
(klipsify (and (assoc 'klipse org-reveal-external-plugins)
(if (not lang)
(format "<pre %s%s>\n%s</pre>"
(or (frag-class frag info) " class=\"example\"")
(if klipsify "style=\"display:none;\" " "")
(if (not caption) ""
(format "<label class=\"org-src-name\">%s</label>"
(org-export-data caption info)))
(format "\n<pre%s%s><code class=\"%s\" %s>%s</code></pre>"
(or (frag-class frag info) "")
label lang code-attribs code)
(format "\n<pre %s%s>%s</pre>"
(or (frag-class frag info)
(format " class=\"src src-%s\"" lang))
(if klipsify (format "<klipse-snippet data-language=\"%s\">%s</klipse-snippet>"
lang code) ""))))))
So far, this seems to work great, though I don’t have access to the DOM of the larger document ,which is sort of a drag.
[UPDATE However, @viebel pointed out to me that you can access the parent frame with: ]:
Pretty cool! Note: klipse will hang if you try to type this in directly. It will only work if you pass the completed line in as part of the initial code block.
Also, this is not a solution that works for rendering HTML pages. For this we need something else. I would like to use RevealEditor, but am not quite there yet (can’t get its code to load properly). So for now I’m embedding a JSBin instance with preoaded code – I just add an iframe tag directly in my org-mode file. It’s not a s pretty or robust, and I can’t see my code when I’m writing, which is too bad, but it’s still pretty useful.
I would really like to hear what other people think! I’d especially like to hear about alternatives or improvements.