implemented numbered lines

with the caveat that things don't overflow:scroll yet :/
This commit is contained in:
m455 2023-02-02 00:39:13 -05:00
parent d676745ec7
commit 5c7d1fdf59
2 changed files with 39 additions and 11 deletions

View file

@ -19,6 +19,14 @@
h1 a[href^="#"]::after, h2 a[href^="#"]::after, h3 a[href^="#"]::after, h4 a[href^="#"]::after, h5 a[href^="#"]::after, h6 a[href^="#"]::after { content: "¶"; opacity: 0; margin-left: .5em; }
h1:hover a[href^="#"]::after, h2:hover a[href^="#"]::after, h3:hover a[href^="#"]::after, h4:hover a[href^="#"]::after, h5:hover a[href^="#"]::after, h6:hover a[href^="#"]::after { opacity: 100; }
h1 a[href^="#"], h2 a[href^="#"], h3 a[href^="#"], h4 a[href^="#"], h5 a[href^="#"], h6 a[href^="#"] { text-decoration: none; }
#file-contents {
white-space: pre;
font-family: monospace;
border-collapse: collapse;
}
#file-contents code {
background-color: inherit;
}
</style>
</head>
<body>

View file

@ -201,13 +201,31 @@
(define (git-repository->paths-list)
(call-with-input-pipe "git ls-tree -r --name-only HEAD" read-lines))
(define (git-file->string source-file)
(define (lines->numbered-lines lines)
`(table
(@ (id "file-contents"))
,@(map (lambda (number line)
`(tr (@ (class "line"))
(td (@ ((class "line-number")
(id ,number)))
(a (@ (href "#" ,number)) ,number))
(td (@ (class "line-contents"))
(code ,line))))
(map number->string (iota (length lines) 1))
lines)))
(define (git-file->string source-file mode)
(let ((handle-lines (lambda (lines)
(if (equal? mode 'plaintext)
(string-intersperse lines "\n")
(lines->numbered-lines lines)))))
(->
source-file
(qs)
((flip format) "git show HEAD:~a")
(call-with-input-pipe read-lines)
(string-intersperse "\n")))
handle-lines)))
;; the result of asking git for some configuration; #f if no result.
(define (git-config->string key)
@ -228,7 +246,9 @@
(define (image-link)
`(p (img (@ (src (,(string-append basename extension)))))))
(define (plaintext)
`(pre ,(git-file->string source-file)))
`(pre ,(git-file->string source-file 'plaintext)))
(define (numbered-lines)
(git-file->string source-file 'table))
(define (binary)
'(p "(Binary file)"))
(case (string->symbol extension)
@ -238,7 +258,7 @@
(format (current-error-port) "Error parsing ~a\n" source-file)
`((p (b "There was an error parsing this file as Markdown."))
,(plaintext)))
(markdown->sxml (git-file->string source-file))))
(markdown->sxml (git-file->string source-file 'plaintext))))
((.jpg .jpeg .png .gif .webp .webm .apng .avif .svgz .ico)
(image-link))
((.svg)
@ -247,7 +267,7 @@
(binary))
(else
(if (git-file-is-text? source-file)
(plaintext)
(numbered-lines)
(binary)))))
(define (filelist->sxml source-files-list relative-root)