Previous: , Up: Tutorial   [Contents]


2.2 Printing Blocks

Blocks can be printed to various output formats, such as strings or SXML.

(use-modules (blocks)
             (blocks language c)
             (blocks printer sxml))

(define my-block (make-block*
                  #:language c
                  #:code "
#include <stdio.h>

int main(void) {
  printf(\"Hello world!\");
}"
                  #:run? #t))

(block->sxml my-block)
;; => $1 = (div ...)
;; An SXML tree structure suitable for HTML insertion.

The #:code and #:result arguments can be used to restrict or modify how the corresponding block fields are printed.

(block->sxml my-block
             #:code 'none)
;; => $1 = (div ...)
;; An SXML tree that does not contain C code, only the block result.