PasteRack.org
Paste # 71000
2019-06-10 18:09:26

Forked from paste # 44478.

Fork as a new paste.

Paste viewed 532 times.


Embed:

  1. #lang racket
  2. (define (handle-paste-gg match)
  3.   (define main-xexp (get-xexp (string-append "https://" (match-url match))))
  4.   (define file-boxes ((sxpath "//div[@class='box']") main-xexp))
  5.   (define (box-raw-url xexp)
  6.     (define relative (match (first ((sxpath "//a") xexp))
  7.                        [`(a ,(list-no-order '@ `(href ,url) _ ...) ,_) url]))
  8.     (string-append "https://paste.gg"
  9.                    ;; XXX: This should probably use some actual HTML entity
  10.                    ;; decoder instead of string-replace.
  11.                    (string-replace relative "/" "/")))
  12.   (cond
  13.     [(empty? file-boxes)
  14.      (raise-user-error "No files in paste")]
  15.     [(= (length file-boxes) 1)
  16.      (values (match-id match)
  17.              (get (box-raw-url (first file-boxes))))]
  18.     [else
  19.      (raise-user-error "Unimplemented")]))

=>