-
Notifications
You must be signed in to change notification settings - Fork 0
/
ox-juslides.el
721 lines (638 loc) · 23.8 KB
/
ox-juslides.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
;; Implement a Jupyter Slides backend for Org mode
;; Specically geared towards the React.JS based
;; presentation mode of Jupyter Notebooks.
;; It is a derived backend from Markdown export
(require 'ox-md)
(require 'dash)
(defgroup org-export-juslides nil
"Options for Jupyer Slides export backend."
:tag "Org Jupyter Slides Notebook"
:group 'org-export
:version "0.1"
:package-version '(Org . "8.0"))
;; TODO: figure out how to put a map
;; of (string, string, string) -> string
;; into a customization variable
;; (defcustom org-export-juslides-beamer-divs
;; '(("theorem" "heading" "pre" "AAA")
;; ("theorem" "heading" "post" "BBB ")
;; ("theorem" "content" "pre" "CCC")
;; ("theorem" "content" "post" "DDD")
;; )
;; "For beamer blocks, which divs should be generated around the header and the content of the corresponding block?"
;; :version "0.1"
;; :group 'org-export-juslides
;; :type '(alist :key-type (string string string)
;; :value-type string)
;; )
(defcustom org-export-juslides-divs-heading-pre
'(("theorem" "<div class=\"theorem-head\" style=\"border:3px; border-style:solid; border-color:#c8bcdd; padding: 5px; background-color:#c8bcdd; line-height:1.5em; text-align:center; border-radius: 15px 15px 0px 0px; margin-bottom: 0; width: 100%;\"><b>Satz: ")
("proof" "<div class=\"proof-head\" style=\"border:3px; border-style:solid; border-color:#c8bcdd; padding: 5px; background-color:#c8bcdd; line-height:1.5em; text-align:center; border-radius: 15px 15px 0px 0px; margin-bottom: 0; width: 100%;\"><b>Beweis: ")
("example" "<div class=\"example-head\" style=\"border:3px; border-style:solid; border-color:#99d19c; padding: 5px; background-color:#99d19c; line-height:1.5em; text-align:center; border-radius: 15px 15px 0px 0px; margin-bottom: 0; width: 100%;\"><b>Beispiel: ")
("note" "<div class=\"note-head\" style=\"border:3px; border-style:solid; border-color:#d1cfcf; padding: 5px; background-color:#d1cfcf; line-height:1.5em; text-align:center; border-radius: 15px 15px 0px 0px; margin-bottom: 0; width: 100%;\"><b>Bemerkung: ")
("definition" "<div class=\"definition-head\" style=\"border:3px; border-style:solid; border-color:#5da9e9; padding: 5px; background-color:#5da9e9; line-height:1.5em; text-align:center; border-radius: 15px 15px 0px 0px; margin-bottom: 0; width: 100%;\"><b>Definition: ")
("quote" "<div class=\"quote-head\" style=\"border:3px; border-style:solid; border-color:#d1cfcf; padding: 5px; background-color:#d1cfcf; line-height:1.5em; text-align:center; border-radius: 15px 15px 0px 0px; margin-bottom: 0; width: 100%;\"><b>Zitat: ")
("alertblock" "<div class=\"alertblock-head\" style=\"border:3px; border-style:solid; border-color:#f96900; padding: 5px; background-color:#f96900; line-height:1.5em; text-align:center; border-radius: 15px 15px 0px 0px; margin-bottom: 0; width: 100%;\"><b>Achtung! ")
)
"Divs to go before the heading"
:type '(alist :key-type string
:value-type (group string))
)
(defcustom org-export-juslides-divs-heading-post
'(("theorem" "</b></div>")
("proof" "</b></div>")
("example" "</b></div>")
("note" "</b></div>")
("definition" "</b></div>")
("quote" "</b></div>")
("alertblock" "</b></div>")
)
"Divs to go after the heading"
:type '(alist :key-type string
:value-type (group string))
)
(defcustom org-export-juslides-divs-content-post
'(("theorem" "\n<div class=\"theorem-content\" style=\"border:3px; border-style:solid; border-color:#c8bcdd; padding: 5px; margin-top: 0; line-height:1.5em; border-radius: 0px 0px 15px 15px; width: 100%; text-align:left;\"></div>")
("proof" "\n<div class=\"proof-content\" style=\"border:3px; border-style:solid; border-color:#c8bcdd; padding: 5px; margin-top: 0; line-height:1.5em; border-radius: 0px 0px 15px 15px; width: 100%; text-align:left\"></div> ")
("example" "\n<div class=\"example-content\" style=\"border:3px; border-style:solid; border-color:#99d19c; padding: 5px; margin-top: 0; line-height:1.5em; border-radius: 0px 0px 15px 15px; width: 100%; text-align:left\"></div> ")
("note" "\n<div class=\"note-content\" style=\"border:3px; border-style:solid; border-color:#d1cfcf; padding: 5px; margin-top: 0; line-height:1.5em; border-radius: 0px 0px 15px 15px; width: 100%; text-align:left\"></div> ")
("definition" "\n<div class=\"definition-content\" style=\"border:3px; border-style:solid; border-color:#5da9e9; padding: 5px; margin-top: 0; border-radius: 0px 0px 15px 15px; width: 100%; text-align:left\"></div>")
("quote" "\n<div class=\"quote-content\" style=\"border:3px; border-style:solid; border-color:#d1cfcf; padding: 5px; margin-top: 0; line-height:1.5em; border-radius: 0px 0px 15px 15px; width: 100%; text-align:left\"></div> ")
("alertblock" "\n<div class=\"alertblock-content\" style=\"border:3px; border-style:solid; border-color:#f96900; padding: 5px; margin-top: 0; line-height:1.5em; border-radius: 0px 0px 15px 15px; width: 100%; text-align:left\"></div> ")
)
"Divs to go before the content"
:type '(alist :key-type string
:value-type (group string))
)
(defcustom org-export-juslides-divs-content-pre
'(("theorem" "")
("proof" "")
("example" "")
("note" "")
("definition" "")
("quote" "")
("alertblock" "")
)
"Divs to go after the content"
:type '(alist :key-type string
:value-type (group string))
)
;; so far, nothing to customize yet :-/
;; TODO: add proper customization variables
;;; Suppress LaTeX output only
(defun org-juslides-export-change-options (plist backend)
(let ( (oldlist (plist-get plist :exclude-tags))
)
(cond
((equal backend 'latex)
(plist-put plist :exclude-tags
(add-to-list 'oldlist '"nolatex")))
((equal backend 'juslides)
(plist-put plist :exclude-tags
(add-to-list 'oldlist '"dropslide" )))
)
)
(print (plist-get plist :exclude-tags))
plist
)
(add-to-list 'org-export-filter-options-functions 'org-juslides-export-change-options)
;;; Define Back-End
(org-export-define-derived-backend 'juslides 'md
; :export-block '("JUSLIDES" "JUSLIDES NOTEBOOK")
:filters-alist '((:filter-final-output . org-juslides-final-function)
; (:filter-link . org-juslides-filter-link)
)
:menu-entry
'(?s "Export to Jupyter Notebook as Slides"
((?b "As temporary MD buffer"
(lambda (a s v b) (org-juslides-export-to-buffer a s v)))
(?f "To file" (lambda (a s v b) (org-juslides-export-to-file a s v)))
))
:translate-alist '((headline . org-juslides-headline)
(bold . org-juslides-bold)
(italic . org-juslides-italic)
; (code . org-juslides-code)
(src-block . org-juslides-src-block)
(inner-template . org-juslides-inner-template)
(latex-fragment . org-juslides-latex-fragment)
(latex-environment . org-juslides-latex-environment)
; TODO: Make sure to set org-html-with-latex to verbatim for this to work!
)
)
;;; Filters
;; none needed so far
;;; Translators
(defun org-juslides-protect-backslash (text)
"Replace any single backslash with two backslahes."
;; Note: the following looks odd, but it really does double a single backslad.
;; Watch out for the second optioal argument, LITERAL = true, to see why.
(replace-regexp-in-string "\\\\" "\\\\" text t t)
)
(defun org-juslides-latex-fragment (latex-fragment _contents info)
(let ( (tmp (org-html-latex-fragment latex-fragment _contents info) )
)
(org-juslides-protect-backslash tmp)
)
)
(defun org-juslides-latex-environment (latex-fragment _contents info)
(let ( (tmp (org-html-latex-environment latex-fragment _contents info)))
(org-juslides-protect-backslash tmp)
)
)
(defun s-trim-right (s)
"Remove whitespace at the end of S."
(if (string-match "[ \t\n\r]+\\'" s)
(replace-match "" t t s)
s))
(defun org-juslides-src-block (src-block contents info)
(let* ( (code (org-export-format-code-default src-block info))
(animate (org-export-read-attribute :attr_juslides src-block :animate))
(tags (org-export-get-tags (org-export-get-parent-headline src-block) info '("invalid" "tags") t))
(skipslide (or (member "skipslide" tags)
(org-export-read-attribute :attr_juslides src-block :skip)
))
)
(message "juslides-src")
(print (s-trim-right code))
(org-juslides-cell "code"
(cond
(skipslide "skip")
(animate "fragment")
(t "-"))
(s-trim-right code))
)
)
(defun org-juslides-get-div (beamertag p1 p2)
"if beamtag is non-nil, grab the divs for the various places.
p1 should be header or content, p2 should be pre or post"
(if beamertag
(let* ((customized-divs (cond
((string= p1 "heading")
(cond
((string= p2 "pre") org-export-juslides-divs-heading-pre)
((string= p2 "post") org-export-juslides-divs-heading-post)
(t nil))
)
((string= p1 "content")
(cond
((string= p2 "pre") org-export-juslides-divs-content-pre)
((string= p2 "post") org-export-juslides-divs-content-post)
(t nil))
)
(t nil))
)
(divstring-tmp (-filter
(lambda (x) (string= beamertag (car x)))
customized-divs))
(divstring-div (car ( cdr (car divstring-tmp))))
(divstring (if divstring-div
divstring-div
""))
)
;; (print "divstring")
;; (print beamertag)
;; (print customized-divs)
;; (print divstring-div)
;; (print divstring)
divstring)
"")
)
(defun org-juslides-format-content (headline contents anchor level info)
"We have a block with a headline. Produce the actual source for this part.
Check for possible BEAMER tags!"
(let* ((tags-list (org-export-get-tags headline info))
; get only those tags that start with B_ for Beamer tag
(beamer-tags (-filter (lambda (x) (string-prefix-p "B_" x))
tags-list))
; let's for now assume there is just a single beamer tag per block heading
(tmp-beamer-tag (car beamer-tags))
(beamer-tag (if tmp-beamer-tag
(substring tmp-beamer-tag 2)
nil))
(heading_pre_div (org-juslides-get-div beamer-tag "heading" "pre"))
(heading_post_div (org-juslides-get-div beamer-tag "heading" "post"))
(content_pre_div (org-juslides-get-div beamer-tag "content" "pre"))
(content_post_div (org-juslides-get-div beamer-tag "content" "post"))
)
(message "juslides-format-content")
; (print heading)
(print level)
(print beamer-tag)
(concat
(if (string= heading_pre_div "")
(concat
(make-string (- level 1) ?#)
" "
heading
anchor
)
(concat
heading_pre_div
; (make-string (- level 1) ?#)
; " "
heading
anchor
heading_post_div
)
)
"\n\n"
content_pre_div
contents
content_post_div
)
)
)
(defun org-juslides-headline (headline contents info)
"Don't show headlines level 1; turn them into a separation slide.
This is based on markdown exporter's headline handling"
(unless (org-element-property :footnote-section-p headline)
(let* ((level (org-export-get-relative-level headline info))
(title (org-export-data (org-element-property :title headline) info))
(todo (and (plist-get info :with-todo-keywords)
(let ((todo (org-element-property :todo-keyword
headline)))
(and todo (concat (org-export-data todo info) " ")))))
(animate (org-export-data (org-element-property :animate headline) info))
(tag-list (and (plist-get info :with-tags)
(org-export-get-tags headline info))
)
(tags (and (plist-get info :with-tags)
(let ((tag-list (org-export-get-tags headline info)))
(and tag-list
(format " :%s:"
(mapconcat 'identity tag-list ":"))))))
;; (skipslide (and tags
;; (or
;; (string-match "skipslide" tags)
;; ; add alternative keywords to skip slides?
;; )
;; ))
(skipslide (member "skipslide" (org-export-get-tags headline info) ))
(animateslide (member "animate" (org-export-get-tags headline info) ))
(notesslide (member "notes" (org-export-get-tags headline info) ))
(subslide (member "subslide" (org-export-get-tags headline info) ))
;; (subslide (and tags
;; (string-match "subslide" tags)))
;; (notesslide (and tags
;; (string-match "notes" tags)))
(priority
(and (plist-get info :with-priority)
(let ((char (org-element-property :priority headline)))
(and char (format "[#%c] " char)))))
(anchor
(and (plist-get info :with-toc)
(format "<a id=\"%s\"></a>"
(or (org-element-property :CUSTOM_ID headline)
(org-export-get-reference headline info)))))
;; Headline text without tags.
(heading (concat todo priority title))
(style (plist-get info :md-headline-style)))
(cond
;; Cannot create a headline. Fall-back to a list.
((or (org-export-low-level-p headline info)
(not (memq style '(atx setext)))
(and (eq style 'atx) (> level 6))
(and (eq style 'setext) (> level 2)))
(let ((bullet
(if (not (org-export-numbered-headline-p headline info)) "-"
(concat (number-to-string
(car (last (org-export-get-headline-number
headline info))))
"."))))
(concat bullet (make-string (- 4 (length bullet)) ?\s) heading tags
"\n\n"
(and contents
(replace-regexp-in-string "^" " " contents)))))
;; Headline level 1?
((eq level 1)
(concat (org-juslides-cell "markdown"
"slide"
;; (concat "Some fancy markup for a section start slide \n\n"
;; heading tags anchor "\n\n")
(org-juslides-tocslide info heading)
)
contents
)
)
;; HEadline level 2, i.e., a normal slide?
((eq level 2)
(concat (org-juslides-cell "markdown"
(cond
(notesslide "notes")
(skipslide "skip")
(subslide "subslide")
(t "slide"))
(concat "# " heading "\n\n" )
)
contents
)
)
;; Ordinary processing
;; Use "Setext" style.
((eq style 'setext)
(concat heading tags anchor "\n"
(make-string (length heading) (if (= level 1) ?= ?-))
"\n\n"
contents))
;; Use "atx" style.
(t (let ((source (org-juslides-format-content headline contents anchor level info))
)
;; (if animateslide
;; (org-juslides-cell "markdown" "fragment" source)
;; (org-juslides-cell "markdown" "-" source)
;; )
(org-juslides-cell "markdown"
(cond
(animateslide "fragment")
(notesslide "notes")
(t "-")
)
source
)
))
;; No further alternatives
))
)
)
(defun org-juslides-bold (_bold contents _info)
"Transcode BOLD object into Markdown format.
CONTENTS is the text within bold markup. INFO is a plist used as
a communication channel."
(format "**%s**" contents))
(defun org-juslides-italic (_italics contents _info)
"Transcode italics/emphasized object into Markdown format."
(format "*%s*" contents))
; not clear, need to look up concrete data structure of "code" objects
;; (defun org-juslides-code (_object contents _info)
;; "Transcode code/fixed-font object into Markdown format."
;; (message (gethash "value" (cdr _object)))
;; (format "--%s--" contents))
;;; Output functions to produce JSON
(defun org-juslides-cell (celltype slidetype source &optional x)
"Produce a JSON-formated cell of celltype, with slidetype
set accordingly. Source is the content of the cell.
The optinal parameter x tells us whether to prepend this block with the closing
brackets for the previous block; x is nil for ordinary blocks and only set to true
for the very first block we crete (i.e., true suppresses prepending of closing brackets."
(format
"%s{
\"cell_type\": \"%s\",
\"metadata\": {
\"slideshow\": {
\"slide_type\": \"%s\"
}
}, %s
\"source\": [[[%s"
(if (not x)
"]]]
},"
"")
celltype
slidetype
(if (equal celltype "code")
"\n\"outputs\": [],
\"execution_count\": null,"
"")
source
)
)
;;; Structure functions: Title slide, Overview slides
(defun org-juslides-titleslide (info)
(let ( (titlestr (org-export-data (plist-get info :title) info))
(author (org-export-data (plist-get info :author) info))
(subtitle
(let ((tmp (plist-get info :subtitle))
)
(if tmp
(org-export-data tmp info)
"")
))
)
(concat "<h1>" titlestr "</h1>\n<p>" subtitle "<p><h2>" author "</h2>" )
)
)
(defun org-juslides-tocslide (info &optional current-title scope)
(let* ((toc
(mapconcat (lambda (entry)
(let* ((number (mapconcat (lambda (x) (format "%d" x))
(org-export-get-headline-number
entry
info)
"."
))
(tmptitle (org-export-get-alt-title entry info))
(strtitle (format "%s" tmptitle))
(title (substring strtitle 1 -1))
(ref (org-export-get-reference entry info))
)
(if (equal title current-title)
(format "1. **<font color=\"red\">%s</font>**" title)
(format "1. %s" title)
)
; TODO: Get HREFs working, but that seems rather nontrivial:
; (format "- <a href=\"%s\">%s</a>" ref title)
))
(org-export-collect-headlines info 1 scope)
"\n"))
)
(format
"<h1>Overview</h1>
%s"
toc)
)
)
;;; High-level funtions
(defun org-juslides-inner-template (contents info)
"Return body of document after converting it to Markdown syntax.
CONTENTS is the transcoded contents string. INFO is a plist
holding export options."
(let ((titleslide (org-juslides-titleslide info))
(overviewslide (org-juslides-tocslide info))
)
(format "{
\"cells\": [
%s
%s
%s
]]]
}
],
\"metadata\": {
\"celltoolbar\": \"Slideshow\",
\"livereveal\": {
\"theme\": \"simple\",
\"transition\": \"none\"
},
\"kernelspec\": {
\"display_name\": \"Python 3\",
\"language\": \"python\",
\"name\": \"python3\"
},
\"language_info\": {
\"codemirror_mode\": {
\"name\": \"ipython\",
\"version\": 3
},
\"file_extension\": \".py\",
\"mimetype\": \"text/x-python\",
\"name\": \"python\",
\"nbconvert_exporter\": \"python\",
\"pygments_lexer\": \"ipython3\",
\"version\": \"3.5.1\"
}
},
\"nbformat\": 4,
\"nbformat_minor\": 0
}"
(org-juslides-cell "markdown" "slide" titleslide t)
(org-juslides-cell "markdown" "slide" overviewslide nil)
contents)))
;;; final filter function
(defun org-juslides-final-function (contents _backend info)
;; work on the buffer to replace the sources strings
;; debugging code, alternative to with-temp-buffer:
;; (setq buffer (generate-new-buffer "juslides"))
;; (set-buffer buffer)
;; (print buffer)
;; (progn
(with-temp-buffer
(insert contents)
(goto-char (point-min))
;; replace the links to figures TODO: build the pngs out of it
(while (re-search-forward "\\(<figures/\\(.*?\\)\\.pdf>\\)" nil t)
(let* ( (filebase (match-string 2))
(pdffile (format "figures/%s.pdf" filebase))
(pngfile (format "figures/%s.png" filebase))
)
(replace-match (format "<center>![imgimg](figures/%s.png)</center>"
(match-string 2)
t t))
(message pdffile)
(message pngfile)
(when (file-newer-than-file-p pdffile pngfile)
(message "run convert on pdf")
(let ( (convertcommand (format "convert -density 300 %s %s"
pdffile
pngfile)))
(message "command is ")
(message convertcommand)
(shell-command convertcommand)
)
)
)
)
(goto-char (point-min))
;; center figures
(while (re-search-forward "\\!\\[img\\]\\(\\(.*\\)\\)" nil t)
(replace-match (concat "<center>![img]"
(match-string 1)
"</center>"))
)
(goto-char (point-min))
;; process the source instructions:
(while (re-search-forward "\"source\": \\[\\[\\[\\(\\(.\\|\n\\)*?\\)\\]\\]\\]" nil t)
; (replace-match decorated)
(let* (
(source (replace-regexp-in-string
"\""
"\\\\\""
(match-string 1)))
(protectedSource (replace-regexp-in-string
"\n"
"\\\\n\",\n\""
source
; (match-string 1)
))
(completeSource (concat "\"" protectedSource "\"\n"))
(sourcedSource (concat "\"source\": [" completeSource "]"))
; we need to get rid of trailing empty lines at the end of a source block:
(cleanupSource (replace-regexp-in-string "\\\\n\",\n\"\\\\n\",\n\"\"" "\"" sourcedSource))
)
; (replace-match sourcedSource)
; (replace-match sourcedSource t t)
(replace-match cleanupSource t t)
)
)
;; nice indentation:
(json-mode)
(mark-whole-buffer)
(indent-for-tab-command)
;; somehow, somewhere, tabs appears :-(
;; they correspond to eight spaces
(goto-char (point-min))
(while (re-search-forward "\t" nil t)
(replace-match " "))
;; RYSE math rendering matces on $ $ and $$...$$, not the more correct \( \) and \[ \]
;; that is produced by org. So we have to swap that back
;; In the json file, we see: \\( -- turn that into regexp
(goto-char (point-min))
(while (re-search-forward "\\\\\\\\(" nil t)
(replace-match "$"))
(goto-char (point-min))
(while (re-search-forward "\\\\\\\\)" nil t)
(replace-match "$"))
;; not that the open bracket needs to be protected by two backslashed itself:
(goto-char (point-min))
(while (re-search-forward "\\\\\\\\\\[" nil t)
(replace-match "$$"))
(goto-char (point-min))
(while (re-search-forward "\\\\\\\\]" nil t)
(replace-match "$$"))
;; return buffer content as resulting string:
(buffer-substring-no-properties (point-min) (point-max))
)
)
;;; Interactive functions
;;;###autoload
(defun org-juslides-export-to-file (&optional async subtreep visible-only body-only ext-plist)
(interactive)
(let* ( (file (org-export-output-file-name ".ipynb" subtreep))
)
(org-export-to-file 'juslides file
async subtreep visible-only body-only ext-plist)
)
)
(defun org-juslides-export-to-buffer (&optional async subtreep visible-only)
"Export current buffer to a Markdown buffer.
If narrowing is active in the current buffer, only export its
narrowed part.
If a region is active, export that region.
A non-nil optional argument ASYNC means the process should happen
asynchronously. The resulting buffer should be accessible
through the `org-export-stack' interface.
When optional argument SUBTREEP is non-nil, export the sub-tree
at point, extracting information from the headline properties
first.
When optional argument VISIBLE-ONLY is non-nil, don't export
contents of hidden elements.
Export is done in a buffer named \"*Org JUSLIDES Export*\", which will
be displayed when `org-export-show-temporary-export-buffer' is
non-nil."
(interactive)
(org-export-to-buffer 'juslides "*Org JUSLIDES Export*"
async subtreep visible-only nil nil (lambda () (json-mode)))
)
;;--------------------
;; possible approach, but does not mesh nicely with editing of code blocks:
;; ;; we need a little helper function to properly export code blocks
;; ;; - when export to latex, export the results as well
;; ;; - when export to slides, only the code
;; ;; usage:
;; ;; #+BEGIN_SRC python :exports (export-by-backend) :results output
;; (defmacro export-by-backend ()
;; `(progn
;; (cond
;; ((org-export-derived-backend-p backend 'latex) "both")
;; ((org-export-derived-backend-p backend 'md) "code")
;; (t "code"))
;; ))
;; a filter to only export code blocks, but no results to juslides
(defun juslides-code-export (backend)
"Ensure that tutor magic markup is removed for Latex export."
(when (org-export-derived-backend-p backend 'juslides)
(replace-regexp ":exports both" ":exports code"))
)
(add-to-list 'org-export-before-processing-hook
'juslides-code-export)
;;;----------------
(provide 'ox-juslides)