diff --git a/main.scm b/main.scm index 29543f7..fa0d8ed 100755 --- a/main.scm +++ b/main.scm @@ -139,6 +139,20 @@ (hr) (footer (p "Generated by " (a (@ href "https://git.m455.casa/repo2html/") "repo2html"))))))) +(define (slugify tag inner) + (-> inner + (pre-post-order* + `( + (*text* . ,(lambda (trig str) + (-> str + (string-translate "/,:;\"[]{}()=+") + (string-translate "ABCDEFGHIJKLMNOPQRSTUVWXYZ _." "abcdefghijklmnopqrstuvwxyz---") + ))) + ,@alist-conv-rules*)))) + +(define (enumerate-tag tag inner) + `(,tag (@ (id ,(slugify tag inner))) ,inner)) + (define (in-git-directory?) (not (eof-object? (call-with-input-pipe "git rev-parse --git-dir" read-line)))) @@ -245,10 +259,19 @@ (SXML->HTML (pre-post-order* (template-wrap->sxml filename sxml) - `((*text* . ,(lambda (trigger str) - (if (equal? str (unspecified-value)) - "" - ((alist-ref '*text* alist-conv-rules*) trigger str)))) + `(;; assign all headings an id so you can link to them + (h1 . ,enumerate-tag) + (h2 . ,enumerate-tag) + (h3 . ,enumerate-tag) + (h4 . ,enumerate-tag) + (h5 . ,enumerate-tag) + ;; i'd expect this to be built-in, dunno why its needed + (*COMMENT* . ,(lambda (tag str) `(""))) + ;; ignore # in tree + (*text* . ,(lambda (trigger str) + (if (equal? str (unspecified-value)) + "" + ((alist-ref '*text* alist-conv-rules*) trigger str)))) ,@alist-conv-rules*)))))) (create-directory html-repo-path #t)