added Tom Marble's slides
[lp17-speaker-slides.git] / Tom-Marble / src / my-deck.el
diff --git a/Tom-Marble/src/my-deck.el b/Tom-Marble/src/my-deck.el
new file mode 100644 (file)
index 0000000..043ec69
--- /dev/null
@@ -0,0 +1,146 @@
+;; elisp for making slides with ox-deck
+;;
+;;
+
+;; NOTE the following customizations
+;;  '(org-deck-directories (list "/home/tmarble/src/github/imakewebthings/deck.js"))
+;;  '(org-deck-postamble "")
+;;  '(org-deck-styles
+;;    "
+;; #title-slide h1 {
+;;     position: static; padding: 0;
+;;     margin-top: 10%;
+;;     -webkit-transform: none;
+;;     -moz-transform: none;
+;;     -ms-transform: none;
+;;     -o-transform: none;
+;;     transform: none;
+;;     font-size: 2em;
+;; }
+;; #title-slide h2 {
+;;     text-align: center;
+;;     border:none;
+;;     padding: 0;
+;;     margin: 5em;
+;;     font-size: 1.2em;
+;; }
+;; .fullscreen {
+;;     position: absolute;
+;;     left: 0px;
+;;     top: 0px;
+;;     width: 100%;
+;;     height: auto;
+;; }
+;; .pad-right {
+;;     margin-right: 1em;
+;; }
+;; .pad-bottom {
+;;     margin-bottom: 3em;
+;;     background: white;
+;; }
+;; .z0 { z-index: 0; }
+;; .z10 { z-index: 10; }
+;; .z20 { z-index: 20; }
+;; table.myable {
+;;   background-color: #ffffff;
+;;   border-collapse: collapse;
+;;   border-width: 2px;
+;;   border-color: #ffcc00;
+;;   border-style: solid;
+;;   color: blue;
+;; }
+;; table.mytable td, table.mytable th {
+;;   border-width: 2px;
+;;   border-color: #ffcc00;
+;;   border-style: solid;
+;;   padding: 3px;
+;; }
+;; table.mytable thead {
+;;   background-color: #ffcc00;
+;; }
+;; table.quiettable, table.quiettable colgroup, table.quiettable tbody, table.quiettable > th, table.quiettable > tr {
+;;   border-style: none;
+;; }
+;; table.quiettable td {
+;;   border-style: none;
+;;   padding: 0 1em;
+;; }
+;; table.quiettable thead {
+;;   border-style: none;
+;; }
+
+;; ")
+;;  '(org-deck-theme "neon.css")
+;;  '(org-deck-title-slide-template "<h1>%t</h1>
+;; <h2>%a &lt;%e&gt;</h2>")
+;;  '(org-export-with-footnotes t)
+
+;; NOTE this mutates prop :(
+(defun text-prop-to-string (prop)
+  "Text property to string"
+  (let* ((start 0)
+         (end (length prop)))
+    (set-text-properties start end nil prop)
+    prop))
+
+(defun org-deck-export-tmarble-html ()
+  "Deck export"
+  (interactive)
+  (message "Starting deck export...")
+  (let* ((export-env (org-export-get-environment))
+         (title (text-prop-to-string (car (plist-get export-env ':title))))
+         (deck-html (concat (replace-regexp-in-string " " "-" title) ".html"))
+         (deck-export-buffer "*Org deck.js Export*")
+         export-dir
+         (find-export-dir
+          (dolist (bfile (mapcar (function buffer-file-name) (buffer-list)))
+            (when (and (not export-dir) bfile (string-suffix-p ".org" bfile))
+              (setq export-dir (file-name-directory bfile)))))
+         ;; assume we found export-dir
+         (export-path (concat export-dir deck-html))
+         ;; Grab all the footnotes
+         (footnotes0 (progn
+                      (goto-char
+                       (org-find-exact-headline-in-buffer "Footnotes" nil t))
+                      (text-prop-to-string (org-get-entry))))
+         (footnotes1 (replace-regexp-in-string
+                      "\\[\\(fn:[0-9]+\\)\\]"
+                      "<li id=\042\\1\042>"
+                      footnotes0))
+         (footnotes (progn
+                      (message footnotes1)
+                      (replace-regexp-in-string
+                       "\\(http[-A-Za-z0-9:/?&.=_]+\\)"
+                       "<a href=\"\\1\">\\1</a>"
+                       footnotes1))))
+
+    ;; Paste Footnotes into References as raw HTML
+    (goto-char (org-find-exact-headline-in-buffer "References" nil t))
+    ;; (org-forward-heading-same-level 1)
+    ;; (insert "\n")
+    ;; (previous-line)
+    ;; delete contents of heading
+    (org-cut-subtree)
+    (insert "* References\n")
+    (insert "Footnote references (press 's' for scrollbars)\n")
+    (insert "#+BEGIN_HTML\n<input type=\"button\" value=\"◁\" onclick=\"window.history.back()\"/>\n<ol>\n")
+    (insert footnotes)
+    (insert "</ol>\n#+END_HTML\n")
+    ;; export the html to deck-export-buffer
+    (org-deck-export-as-html)
+    ;; s/outline-container-sec/slide/g
+    (replace-regexp "outline-container-sec" "slide" nil (point-min) (point-max))
+    ;; find the last slide and rename it to references
+    (goto-char (point-max))
+    (search-backward "id=\"slide-")
+    (replace-regexp "slide-[0-9]+" "references")
+    ;; change all footnote anchors to #references
+    (goto-char (point-min))
+    (replace-regexp "_org_" "org")
+    (replace-regexp "#fn\.[0-9]+" "#references")
+    ;; write file
+    (write-file export-path) ;; changes buffer name...
+    (message (concat "Exported deck to " deck-html))
+    ;; (kill-buffer deck-export-buffer)
+    (kill-buffer (current-buffer))
+    ))