summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.org>2026-02-14 10:07:36 -0500
committerJakob L. Kreuze <zerodaysfordays@sdf.org>2026-02-14 10:07:36 -0500
commitf62a80e1a10970376973a2ee5b016a814bcd2039 (patch)
tree90a224a7adfa4d78c76651cf3db9ae8212104637
parent58405b074faec581cf7f74acff1397193e04138c (diff)
Rewrite code blocks
-rw-r--r--jakob/utils/org-mode.scm35
-rw-r--r--static/css/style.css8
2 files changed, 34 insertions, 9 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)))
diff --git a/static/css/style.css b/static/css/style.css
index 6c3a196..49b1f88 100644
--- a/static/css/style.css
+++ b/static/css/style.css
@@ -669,7 +669,7 @@ pre {
}
}
-figure {
+figure:not(.code-container) {
margin: 20px 0;
padding: 10px;
background-color: #f9f9f9;
@@ -677,7 +677,7 @@ figure {
box-shadow: 2px 2px 0#ccc
}
-figure img {
+figure:not(.code-container) img {
display: block;
max-width: 100%;
height: auto;
@@ -685,7 +685,7 @@ figure img {
margin-bottom: 10px
}
-figcaption {
+figure:not(.code-container) figcaption {
font-size: 9px;
color: #666;
line-height: 1.2;
@@ -693,7 +693,7 @@ figcaption {
border-top: 1px dotted #999
}
-figcaption .figure-number {
+figure:not(.code-container) figcaption .figure-number {
font-weight: 700;
text-transform: uppercase;
color: #333