Merge pull request #257 from titaniumbones/klipse-support

Support for live execution of code snippets
This commit is contained in:
Yujie Wen 2018-06-20 00:33:11 +08:00 committed by GitHub
commit 9df5f02b7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 15 deletions

View File

@ -511,6 +511,13 @@ Store the names and loading instructions for each plugin in the defcustom ~org-r
The "%r" in the given CSS file name will be replaced by Reveal.js'
URL.
** Editable Source Code
It is now possible to embed code blocks in a codemirror instance in order to edit code during a presentation. At present, this capacity is turned on or off at time export using these defcustoms:
- ~org-reveal-klipsify-src~
- ~org-reveal-klipse-css~
- ~org-reveal-klipse-js~
TThis feature is turned off by default and needs to be switched on with ~org-reveal-klipsify-src~. At present couce editing is supported in javacript, clojure, php, ruby, scheme, and pyhton only.
** MathJax
:PROPERTIES:
:CUSTOM_ID: my-heading
@ -713,7 +720,7 @@ Store the names and loading instructions for each plugin in the defcustom ~org-r
custom-id, as the examples below:
* [[Tips]].
* [[#my-heading][Heading]] with a =CUSTOM_ID= property.
* [[#my-heading][Heading]] with a =CUSTOM_ID= property.q
** Custom JS
@ -721,6 +728,25 @@ Store the names and loading instructions for each plugin in the defcustom ~org-r
~#+REVEAL_INIT_SCRIPT~ (multiple statements are concatenated) or by
custom variable ~org-reveal-init-script~.
** Executable Source Blocks
To allow live execution of code in some languages, enable the klipsify plugin by setting ~org-reveal-klipsify-src~ to non-nil. Src blocks with the languages ~js~, ~clojure~, ~html~, ~python~, ~ruby~, ~scheme~, ~php~ will be executed with output shown in a console-like environment. See the source code of ~org-reveal-src-block~ for more details.
*** HTML Src Block
#+BEGIN_SRC html
<h1 class="whatever">hello, what's your name</h1>
#+END_SRC
*** Javascript Src Block
#+BEGIN_SRC js
console.log("success");
var x='string using single quote';
x
#+END_SRC
*** Perl Src Block (not klipsified)
#+BEGIN_SRC perl
I don't know perl!
#+END_SRC
* Thanks
Courtesy to:

View File

@ -371,6 +371,21 @@ BEFORE the plugins that depend on them."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-klipsify-src nil
"Set to non-nil if you would like to make source code blocks editable in exported presentation."
:group 'org-export-reveal
:type 'boolean)
(defcustom org-reveal-klipse-css "https://storage.googleapis.com/app.klipse.tech/css/codemirror.css"
"Location of the codemirror css file for use with klipse."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-klipse-js "https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"
"location of the klipse js source code."
:group 'org-export-reveal
:type 'string)
(defvar org-reveal--last-slide-section-tag ""
"Variable to cache the section tag from the last slide. ")
@ -993,25 +1008,61 @@ contextual information."
:attr_reveal src-block :code_attribs) ""))
(label (let ((lbl (org-element-property :name src-block)))
(if (not lbl) ""
(format " id=\"%s\"" lbl)))))
(format " id=\"%s\"" lbl))))
(klipsify (and org-reveal-klipsify-src
(member lang '("javascript" "js" "ruby" "scheme" "clojure" "php" "html"))))
(langselector (cond ((or (string= lang "js") (string= lang "javascript")) "selector_eval_js")
((string= lang "clojure") "selector")
((string= lang "python") "selector_eval_python_client")
((string= lang "scheme") "selector_eval_scheme")
((string= lang "ruby") "selector_eval_ruby")
((string= lang "html") "selector_eval_html"))
)
)
(if (not lang)
(format "<pre %s%s>\n%s</pre>"
(or (frag-class frag info) " class=\"example\"")
label
code)
(format
"<div class=\"org-src-container\">\n%s%s\n</div>"
(if (not caption) ""
(format "<label class=\"org-src-name\">%s</label>"
(org-export-data caption info)))
(if use-highlight
(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))
label code)))))))
(if klipsify
(concat
"<iframe style=\"background-color:white;\" height=\"500px\" width= \"100%\" srcdoc='<html><body><pre><code "
(if (string= lang "html" )"data-editor-type=\"html\" " "") "class=\"klipse\" "code-attribs ">
" (if (string= lang "html")
(replace-regexp-in-string "'" "&#39;"
(replace-regexp-in-string "&" "&amp;"
(replace-regexp-in-string "<" "&lt;"
(replace-regexp-in-string ">" "&gt;"
(cl-letf (((symbol-function 'org-html-htmlize-region-for-paste)
#'buffer-substring))
(org-html-format-code src-block info))))))
(replace-regexp-in-string "'" "&#39;"
code)) "
</code></pre>
<link rel= \"stylesheet\" type= \"text/css\" href=\"" org-reveal-klipse-css "\">
<style>
.CodeMirror { font-size: 2em; }
</style>
<script>
window.klipse_settings = { " langselector ": \".klipse\" };
</script>
<script src= \"" org-reveal-klipse-js "\"></script></body></html>
'>
</iframe>")
(format
"<div class=\"org-src-container\">\n%s%s\n</div>"
(if (not caption) ""
(format "<label class=\"org-src-name\">%s</label>"
(org-export-data caption info)))
(if use-highlight
(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))
label code)
)))))))
(defun org-reveal-quote-block (quote-block contents info)
"Transcode a QUOTE-BLOCK element from Org to Reveal.