writeups/scripts/writefreely-validate

40 lines
1004 B
Racket
Executable File

#!/usr/bin/env racket
#lang racket/base
(require json
racket/list
racket/port
racket/pretty)
(define current-header (make-parameter #f))
(define (check-block blk)
(define c (hash-ref blk 'c))
(define t (hash-ref blk 't))
(when (equal? t "Header")
(current-header (first (second c))))
(when (equal? t "CodeBlock")
(define content (second c))
(for ([line (in-lines (open-input-string content))])
(when (> (string-length line) 80)
(eprintf "WARNING: [#~a] found code line > 80\n" (current-header))))))
(define (check-any thing)
(when (list? thing)
(for-each check-any thing))
(when (hash? thing)
(when (and (hash-has-key? thing 'c) (hash-has-key? thing 't))
(check-block thing))
(for-each check-any (hash-values thing))))
(define (check-ast doc-ast)
(check-any (hash-ref doc-ast 'blocks)))
(module+ main
(define doc-ast (read-json))
(current-header "<top level>")
(check-ast doc-ast)
(write-json doc-ast))