Welcome to the CHICKEN Scheme pasting service

wiki2html.scm added by mario-goulart on Wed Nov 11 20:37:17 2020

#| -*- scheme -*-
exec csi -s $0 "$@"

  (use qwiki utils svnwiki-sxml sxml-transforms))
  (import (chicken format)
          (chicken pathname)
          (chicken port)
          (chicken process-context)
          (chicken string))
  (import qwiki svnwiki-sxml sxml-transforms srfi-1 srfi-13))
  (error "Unsupported CHICKEN version.")))

(define sxml->html
  (let ((rules `((literal *preorder* . ,(lambda (t b) b))
                 . ,universal-conversion-rules*)))
    (lambda (sxml)
        (lambda ()
          (SRV:send-reply (pre-post-order* sxml rules)))))))

(define (read-wiki-file file)
    (lambda ()
       (call-with-input-file file svnwiki->sxml)))))

(define (wiki->html file #!key title css menu)
   `((literal "<!DOCTYPE html>")
       (title ,(or title "CHICKEN Scheme"))
       (meta (@ (http-equiv "Content-Type")
                (content "application/xhtml+xml; charset=utf-8")))
       (link (@ (rel "stylesheet")
                (href ,(if css
                (type "text/css")))
       (link (@ (rel "icon")
                (href "http://call-cc.org/favicon.ico")
                (type "image/x-icon"))))
      ,(if menu
           `(div (@ (id "menu"))
                 (literal ,(read-wiki-file menu)))
      (div (@ (id "content"))
           (literal ,(read-wiki-file file)))))))

(define (usage #!optional exit-code)
  (let ((port (if (and exit-code (not (zero? exit-code)))
    (fprintf port
             "~a [--css <css URI>] [--title <page title>] [--menu <menu file>] <wiki-file>\n"
             (pathname-strip-directory (program-name)))
    (when exit-code (exit exit-code))))

(let ((wiki-file #f)
      (css #f)
      (title #f)
      (menu-file #f))
  (let loop ((args (command-line-arguments)))
    (if (null? args)
        (if wiki-file
            (print (wiki->html wiki-file
                               css: css
                               title: title
                               menu: menu-file))
            (usage 1))
        (let ((arg (car args)))
          (cond ((or (equal? arg "-h")
                     (equal? arg "--help"))
                 (usage 0))
                ((equal? arg "--css")
                 (set! css (cadr args))
                 (loop (cddr args)))
                ((equal? arg "--title")
                 (set! title (cadr args))
                 (loop (cddr args)))
                ((equal? arg "--menu")
                 (set! menu (cadr args))
                 (loop (cddr args)))
                 (set! wiki-file arg)
                 (loop (cdr args))))))))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Type in the text below:
  ___   __ _(_)_ __ ___  _ __ 
 / _ \ / _` | | '_ ` _ \| '__|
| (_) | (_| | | | | | | | |   
 \___/ \__, |_|_| |_| |_|_|   
Visually impaired? Let me spell it for you (wav file) download WAV