2626 (struct paragraph ([content content?]))
2727 (struct code-block ([content content?] [language (or/c #f string?)]))
2828 (struct unordered-list ([blockss (listof (listof block?))]))
29- (struct ordered-list ([blockss (listof (listof block?))]))
29+ (struct ordered-list ([start exact-positive-integer?]
30+ [blockss (listof (listof block?))]))
3031 (struct blockquote ([blocks (listof block?)]))
3132 (struct html-block ([xexpr xexpr/c]))
3233
3940(struct paragraph (content) #:transparent )
4041(struct code-block (content language) #:transparent )
4142(struct unordered-list (blockss) #:transparent )
42- (struct ordered-list (blockss) #:transparent )
43+ (struct ordered-list (start blockss) #:transparent )
4344(struct blockquote (blocks) #:transparent )
4445(struct html-block (xexpr) #:transparent )
4546(define-values [horizontal-rule horizontal-rule?]
6263(define (spaces/p n) (repeat/p n (char/p #\space )))
6364(define maybe-indent/p (map/p length (many/p (char/p #\space ))))
6465
65- (define unordered-list-bullet/p (or/p (string/p "* " ) (string/p "- " )))
66- (define ordered-list-bullet/p (do integer/p (string/p ". " )))
66+ (define unordered-list-bullet/p (do ( or/p (string/p "* " ) (string/p "- " )) (pure #f )))
67+ (define ordered-list-bullet/p (do [n <- integer/p] (string/p ". " ) (pure n )))
6768
6869;; -----------------------------------------------------------------------------
6970
@@ -125,7 +126,7 @@ As it parses the indentation for each block, it transfers it from the
125126`out-blocks` stack to the `in-blocks` stack, morally “entering” the block. |#
126127
127128; see Note [Open blocks]
128- (struct open-list (type indent blockss) #:transparent )
129+ (struct open-list (start indent blockss) #:transparent )
129130(struct list-element (indent blocks) #:transparent )
130131(struct footnote (name blocks) #:transparent )
131132
@@ -137,10 +138,10 @@ As it parses the indentation for each block, it transfers it from the
137138
138139(define (close-block block)
139140 (match block
140- [(open-list 'unordered _ blockss) (unordered-list blockss)]
141- [(open-list 'ordered _ blockss) (ordered-list blockss)]
142- [(paragraph content) (paragraph (simplify-content content))]
143- [_ block]))
141+ [(open-list #f _ blockss) (unordered-list blockss)]
142+ [(open-list start _ blockss) (ordered-list start blockss)]
143+ [(paragraph content) (paragraph (simplify-content content))]
144+ [_ block]))
144145
145146; Closes a sequence of open blocks. Returns two values:
146147; 1. a list of (closed) blocks
@@ -158,11 +159,11 @@ As it parses the indentation for each block, it transfers it from the
158159
159160(define (add-blocks open-block new-blocks)
160161 (match open-block
161- [(document blocks targets notes) (document (append blocks new-blocks) targets notes)]
162- [(open-list type indent blockss) (open-list type indent (append blockss (map list-element-blocks new-blocks)))]
163- [(list-element indent blocks) (list-element indent (append blocks new-blocks))]
164- [(blockquote blocks) (blockquote (append blocks new-blocks))]
165- [(footnote name blocks) (footnote name (append blocks new-blocks))]))
162+ [(document blocks targets notes) (document (append blocks new-blocks) targets notes)]
163+ [(open-list start indent blockss) (open-list start indent (append blockss (map list-element-blocks new-blocks)))]
164+ [(list-element indent blocks) (list-element indent (append blocks new-blocks))]
165+ [(blockquote blocks) (blockquote (append blocks new-blocks))]
166+ [(footnote name blocks) (footnote name (append blocks new-blocks))]))
166167
167168(define (add-footnotes doc new-notes)
168169 (define notes (append (document-footnotes doc) new-notes))
@@ -261,10 +262,10 @@ As it parses the indentation for each block, it transfers it from the
261262
262263 ; If we’re in a list (but not a list element), parse a new list element.
263264 ; See Note [Unconditionally parse list elements] for why we don’t have to handle anything else.
264- [(open-list 'unordered _ _ )
265+ [(open-list #f _ _ )
265266 (do unordered-list-bullet/p
266267 (scan-block-content (list-element 2 '() ) (cons inner-block in-blocks)))]
267- [(open-list 'ordered _ _ )
268+ [(open-list _ _ _ )
268269 (do [bullet <- (syntax-box/p ordered-list-bullet/p)]
269270 (scan-block-content (list-element (srcloc-span (syntax-box-srcloc bullet)) '() )
270271 (cons inner-block in-blocks)))]
@@ -306,8 +307,8 @@ As it parses the indentation for each block, it transfers it from the
306307 (scan-line-start (reverse (list* (code-block "" language) inner-block in-blocks))))
307308
308309 ; lists
309- (scan-list-start (cons inner-block in-blocks) 'unordered unordered-list-bullet/p)
310- (scan-list-start (cons inner-block in-blocks) 'ordered ordered-list-bullet/p)
310+ (scan-list-start (cons inner-block in-blocks) unordered-list-bullet/p)
311+ (scan-list-start (cons inner-block in-blocks) ordered-list-bullet/p)
311312
312313 ; html blocks
313314 (do (lookahead/p (or/p (try/p (string/p "<div " ))
@@ -334,11 +335,12 @@ As it parses the indentation for each block, it transfers it from the
334335 (many/p (char/p #\space ))
335336 (scan-block-content (footnote name '() ) in-blocks)))
336337
337- (define (scan-list-start in-blocks type start-p)
338- (do [indent <- (try/p (do [indent <- maybe-indent/p]
339- (lookahead/p start-p)
340- (pure indent)))]
341- (scan-block-content (open-list type indent '() ) in-blocks)))
338+ (define (scan-list-start in-blocks start-p)
339+ (do [(list indent start)
340+ <- (try/p (do [indent <- maybe-indent/p]
341+ [start <- (lookahead/p start-p)]
342+ (pure (list indent start))))]
343+ (scan-block-content (open-list start indent '() ) in-blocks)))
342344
343345#| Note [Unconditionally parse list elements]
344346~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments