diff options
| -rw-r--r-- | main.scm | 21 | ||||
| -rw-r--r-- | style.css | 13 | 
2 files changed, 32 insertions, 2 deletions
| @@ -179,6 +179,23 @@  (define (get-opt opt opts) (find (cut equal? <> opt) opts)) +(define (content->sxml content) +  (let ([r "(https://[^ ]*)"]) +    (if (irregex-search r content) +      (let* ([starts-with-link (= 0 (irregex-match-start-index (irregex-search r content)))] +             [texts (map (cut list 'div '(@ [class "content-text"]) <>) (irregex-split r content))] +             [links (map (lambda (x) `(a (@ [href ,x] [class "content-link"]) ,x)) (irregex-extract r content))]) +        (define (go xs ys take-y?) +          (cond +            [(and (not (null-list? ys)) take-y?) +             (cons (car ys) (go xs (cdr ys) #f))] +            [(and (not (null-list? xs)) (not take-y?)) +             (cons (car xs) (go (cdr xs) ys #t))] +            [else '()] +            )) +        (go texts links starts-with-link)) +      `(p ,content)))) +  (define (post current-user p . opts)      (let ([uri (post-path (id p))]            [hide-comments-link (get-opt 'hide-comments-link opts)]) @@ -196,8 +213,8 @@                           [style "max-width:100%;"]                           [loading "lazy"]))                  '()) -            (p (@ [style "min-height:0.5em;white-space:pre-wrap;"]) ,(content p)) -            (div [@ (class "post-info")] +            (div (@ [class "content-container"]) ,(content->sxml (content p))) +            (div (@ [class "post-info"])                   (em "- " (a (@ [href ,(user-path (user p))]) ,(user p)))                   (span (@ [style "float:right;"])                         ,(if hide-comments-link '() `(a (@ [href ,uri] [style "margin-right:2px;"]) @@ -195,3 +195,16 @@ textarea {        width: 100%;    }  } + +.content-container { +    min-height:0.5em; +    white-space:pre-wrap; +} + +.content-link { +  display: inline-block; +} + +.content-text { +  display: inline-block; +} | 
