From 21793fb83ef51a522acadde51c98299f7e84b293 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Sat, 10 Dec 2022 21:41:13 +0100 Subject: [PATCH] Allow \r in pre terminators --- tekuti/marxdown.scm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tekuti/marxdown.scm b/tekuti/marxdown.scm index c268e6b..b6cd133 100644 --- a/tekuti/marxdown.scm +++ b/tekuti/marxdown.scm @@ -132,13 +132,28 @@ (unget chars)))) (define (next) (get-char port)) + (define (peek) (peek-char port)) + (define (next-not-eof ctx) (let ((ch (next))) (if (eof-object? ch) (error "EOF while reading" ctx) ch))) - (define (next-line-and-delim) (read-line port 'split)) - (define (peek) (peek-char port)) + (define (next-line-and-delim) + (let lp ((chars '())) + (define (finish delim) + (cons (reverse-list->string chars) delim)) + (let ((ch (next))) + (cond + ((eof-object? ch) (finish ch)) + ((eqv? ch #\return) + (if (eqv? (peek) #\newline) + (finish (next)) + (lp (cons ch chars)))) + ((eqv? ch #\newline) + (finish ch)) + (else + (lp (cons ch chars))))))) (define (skip-whitespace k) (let lp ((indent 0))