2023-09-19 03:39:16 +00:00
|
|
|
#!/usr/bin/env racket
|
|
|
|
#lang racket/base
|
|
|
|
|
|
|
|
(require json
|
|
|
|
racket/list
|
2024-01-22 03:12:40 +00:00
|
|
|
racket/match
|
2023-09-19 03:39:16 +00:00
|
|
|
racket/port
|
|
|
|
racket/pretty)
|
|
|
|
|
2024-01-22 03:12:40 +00:00
|
|
|
(define link-base (make-parameter #f))
|
|
|
|
(define embed-base (make-parameter #f))
|
|
|
|
|
2023-09-19 03:39:16 +00:00
|
|
|
(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))))
|
|
|
|
|
2024-01-22 03:12:40 +00:00
|
|
|
(define (hash-ref* table keys)
|
|
|
|
(match keys
|
|
|
|
['() table]
|
|
|
|
[(cons key rst) (hash-ref* (hash-ref table key #f) rst)]))
|
|
|
|
|
2023-09-19 03:39:16 +00:00
|
|
|
(define (check-ast doc-ast)
|
2024-01-22 03:12:40 +00:00
|
|
|
(link-base (hash-ref* doc-ast '(meta wf-link-base c)))
|
|
|
|
(embed-base (hash-ref* doc-ast '(meta wf-embed-base c)))
|
2023-09-19 03:39:16 +00:00
|
|
|
(check-any (hash-ref doc-ast 'blocks)))
|
|
|
|
|
2024-01-22 03:12:40 +00:00
|
|
|
(define (transform-ast doc-ast)
|
|
|
|
;; todo
|
|
|
|
doc-ast)
|
|
|
|
|
2023-09-19 03:39:16 +00:00
|
|
|
(module+ main
|
2024-01-22 03:12:40 +00:00
|
|
|
(require racket/cmdline)
|
|
|
|
|
|
|
|
(command-line
|
|
|
|
#:program "writefreely-validate"
|
|
|
|
#:args (doctype)
|
|
|
|
(define doc-ast (read-json))
|
|
|
|
(current-header "<top level>")
|
|
|
|
(check-ast doc-ast)
|
|
|
|
(write-json (transform-ast doc-ast))))
|