From 3833395a2cba6573fcdeda0be5eb047f83293643 Mon Sep 17 00:00:00 2001 From: pho4cexa Date: Wed, 7 Dec 2022 16:17:48 -0800 Subject: [PATCH] handle markdown parser errors, (some) binary files also don't attempt to render (some) binary files we need to figure out a better heuristic for detecting what's a viewable file and what's not. git has something built-in for diffs but i don't know where it lives to trigger it. .gitattributes lets you configure it but there are also built-in rules it has as well. there's other mechanisms to detect filetype like file(1) that we could call out to. maybe there's an egg for it but i haven't found it --- main.scm | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/main.scm b/main.scm index 39d0a3c..5b71f4d 100755 --- a/main.scm +++ b/main.scm @@ -90,21 +90,33 @@ string-block (define (display-source-html source-file) ;; src/main.scm (format #t "

~a

" source-file) - (case (string->symbol (or (pathname-extension source-file) "")) + (case (string->symbol (or (pathname-extension source-file) "no-extension")) ((md markdown) - (markdown->html (git-file->string source-file))) + (handle-exceptions exn + (begin + (display "Error parsing " (current-error-port)) + (display source-file (current-error-port)) + (display "\n" (current-error-port)) + (display "

There was an error parsing this file as Markdown.

") + (display "
")
+            (display-escaped-html (git-file->string source-file))
+            (display "
")) + (markdown->html (git-file->string source-file)))) ((jpg jpeg png gif webp webm apng avif svgz ico) - (format #t "

" source-file) - ) + (format #t "

" source-file)) ((svg) (format #t "

" source-file) (display "
")
      (display-escaped-html (git-file->string source-file))
      (display "
")) - (else + ((gz pack idx) + (display "

(Binary file)

")) + ((txt no-extension) (display "
")
      (display-escaped-html (git-file->string source-file))
-     (display "
")))) + (display "")) + (else + (display "

(Unknown file type)

")))) (define (display-files-html source-files-list) (display "