summaryrefslogtreecommitdiff
path: root/jakob
diff options
context:
space:
mode:
Diffstat (limited to 'jakob')
-rw-r--r--jakob/utils/org-mode.scm35
1 files changed, 30 insertions, 5 deletions
diff --git a/jakob/utils/org-mode.scm b/jakob/utils/org-mode.scm
index fdaaa06..648f9d6 100644
--- a/jakob/utils/org-mode.scm
+++ b/jakob/utils/org-mode.scm
@@ -31,6 +31,7 @@
#:use-module (ice-9 textual-ports)
#:use-module (jakob utils)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-11)
#:use-module (srfi srfi-19)
#:use-module (srfi srfi-26)
#:use-module (srfi-197)
@@ -182,8 +183,32 @@ daemon. Assumes that FORM does not write to `standard-output'."
(%cache-directory)))
((not (file-exists? (%cache-directory)))
(mkdir (%cache-directory)))))
- (if (and (%cache-directory)
- (file-exists? (metadata-file-name hash))
- (file-exists? (sxml-file-name hash)))
- (read-org-mode-file-cached hash)
- (read-org-mode-file-fresh hash file-name)))
+ (let-values (((metadata sxml)
+ (if (and (%cache-directory)
+ (file-exists? (metadata-file-name hash))
+ (file-exists? (sxml-file-name hash)))
+ (read-org-mode-file-cached hash)
+ (read-org-mode-file-fresh hash file-name))))
+ (values metadata (rewrite-org-mode sxml))))
+
+;;; Rewriting engine
+
+(define (rewrite-org-mode tree)
+ (define filters (list rewrite-code-blocks-as-figures))
+ (fold (lambda (f value) (f value)) tree filters))
+
+(define (rewrite-code-blocks-as-figures tree)
+ (match tree
+ (('div ('@ ('class "org-src-container")) "\n"
+ ('pre ('@ ('class class))
+ code ...)
+ rest ...)
+ `(figure (@ (class "code-container"))
+ (figcaption (@ (class "code-header"))
+ ;; (span (@ (class "code-filename")))
+ (span (@ (class "code-lang")) ,class))
+ (pre (code ,code)))
+ )
+ ((xs ...)
+ (map rewrite-code-blocks-as-figures xs))
+ (elem elem)))