[racket] Scribble source file with inline images

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jun 3 16:14:23 EDT 2014

The piece that can't handle non-character input is the `@` reader.

You can avoid it by a kind of `include`, so that a plain Racket reader
is used to get the source. This almost works:

 #lang scribble/manual
 @(require (for-syntax racket/base
                       syntax/strip-context
                       (prefix-in s: scribble/comment-reader)))

 @(define-syntax (flappy-bird stx)
    (define mod
      (call-with-input-file*
       "flappy-bird.rkt"
       (lambda (i) 
         (port-count-lines! i)
         (s:read-syntax (object-name i) i))))
    (syntax-case (replace-context #'here mod) ()
      [(modu name lang (mod-beg form ...))
       #'@racketblock[form ...]]))

 @(flappy-bird)

Unfortunately, the images still show up as `#(struct:object:image%
...)`. The problem is that the images are produced by `read-syntax`
(the one that handles comments) at compile time, so they're
compile-time images; they're not recognized as convertible to bitmaps
at the document's run-time. We have to change each syntax-object image
to an escaped expression that puts the bytes for the image into a
run-time convertible value.

The enclosed "flappy.scrbl" fills in the last step. The `bridge-images`
function converts an image to an expression #,(png-bytes <bytes>),
where a `png-bytes` is convertible to 'png-bytes.

At Tue, 3 Jun 2014 21:09:44 +0200, Jens Axel Søgaard wrote:
> Hi all,
> 
> I have the following source file which contains inline images:
> 
>     https://github.com/soegaard/flappy-bird/blob/master/flappy-bird.rkt
> 
> I'd like to use Scribble to pretty print it to html.
> 
> I tried wrapping the source in a  racketblock, but I get an error
> concerning the inline images "Only pure text files supported".
> 
> Is there a different way of doing what I want?
> 
> -- 
> Jens Axel Søgaard
> 
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flappy.scrbl
Type: application/octet-stream
Size: 1302 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20140603/e2854284/attachment.obj>

Posted on the users mailing list.