|
106 | 106 | ;; By default, `add-block!` also closes any unentered containers, which is
|
107 | 107 | ;; generally the right choice, since the start of a new block always closes
|
108 | 108 | ;; any unentered containers. However, functions like `close-leaf!` and
|
109 |
| - ;; `close-container!` call `add-block!` to close a previously-opened block, |
110 |
| - ;; which should always be added to the innermost open container, so those |
111 |
| - ;; functions set #:close-entered? to #f. |
| 109 | + ;; `close-container!` call `add-block!` as part of the process of closing |
| 110 | + ;; unentered containers, so they pass `#:close-unentered? #f` to avoid |
| 111 | + ;; infinite recursion. |
112 | 112 | (define (add-block! block #:close-unentered? [close-unentered? #t])
|
113 | 113 | (when close-unentered?
|
114 | 114 | (close-unentered-containers!))
|
|
178 | 178 | ; If there’s an open leaf, we need to take care to close it /before/ we
|
179 | 179 | ; remove the open container.
|
180 | 180 | (close-leaf!)
|
181 |
| - (define new-block |
182 |
| - (match (gvector-remove-last! open-containers) |
183 |
| - [(o:blockquote blocks) |
184 |
| - (blockquote (reverse blocks))] |
185 |
| - [(? o:list? open-list) |
186 |
| - ; see Note [Transfer `end-blank?` to parent lists] |
187 |
| - (when (and (o:list-end-blank? open-list) |
188 |
| - (not (zero? (gvector-count open-containers)))) |
189 |
| - (define last-idx (sub1 (gvector-count open-containers))) |
190 |
| - (define parent-container (gvector-ref open-containers last-idx)) |
191 |
| - (when (o:list? parent-container) |
192 |
| - (gvector-set! open-containers |
193 |
| - last-idx |
194 |
| - (struct-copy o:list parent-container |
195 |
| - [end-blank? #t])))) |
196 |
| - |
197 |
| - (itemization (reverse (accumulate-list-blockss open-list)) |
198 |
| - (o:list-style open-list) |
199 |
| - (o:list-start-num open-list))] |
200 |
| - [(o:footnote-definition blocks label) |
201 |
| - (gvector-add! footnote-defns (footnote-definition (reverse blocks) label)) |
202 |
| - #f])) |
203 |
| - (when new-block |
204 |
| - (add-block! new-block #:close-unentered? #f))) |
| 181 | + (match (gvector-remove-last! open-containers) |
| 182 | + [(o:blockquote blocks) |
| 183 | + (add-block! (blockquote (reverse blocks)) #:close-unentered? #f)] |
| 184 | + |
| 185 | + [(? o:list? open-list) |
| 186 | + (add-block! (itemization (reverse (accumulate-list-blockss open-list)) |
| 187 | + (o:list-style open-list) |
| 188 | + (o:list-start-num open-list)) |
| 189 | + #:close-unentered? #f) |
| 190 | + |
| 191 | + ; See Note [Transfer `end-blank?` to parent lists]. |
| 192 | + (when (and (o:list-end-blank? open-list) |
| 193 | + (not (zero? (gvector-count open-containers)))) |
| 194 | + (define last-idx (sub1 (gvector-count open-containers))) |
| 195 | + (define parent-container (gvector-ref open-containers last-idx)) |
| 196 | + (when (o:list? parent-container) |
| 197 | + (gvector-set! open-containers |
| 198 | + last-idx |
| 199 | + (struct-copy o:list parent-container |
| 200 | + [end-blank? #t]))))] |
| 201 | + |
| 202 | + [(o:footnote-definition blocks label) |
| 203 | + (gvector-add! footnote-defns (footnote-definition (reverse blocks) label))])) |
205 | 204 |
|
206 | 205 | (define (unentered-containers?)
|
207 | 206 | (< entered-containers (gvector-count open-containers)))
|
@@ -959,6 +958,24 @@ inner list, not the outer one. Therefore, to ensure the outer list is properly
|
959 | 958 | marked loose, we must transfer the value of `end-blank?` to any immediately-
|
960 | 959 | enclosing parent list whenever a list is closed.
|
961 | 960 |
|
| 961 | +Note that it is critical that we perform this transfer /after/ we’ve already |
| 962 | +added the child list to the parent. If we transferred `end-blank?` to the parent |
| 963 | +/before/ adding the child list, we’d accidentally interpret |
| 964 | +
|
| 965 | + * foo⏎ |
| 966 | + * bar⏎ |
| 967 | + ⏎ |
| 968 | +
|
| 969 | +essentially as if it were |
| 970 | +
|
| 971 | + * foo⏎ |
| 972 | + ⏎ |
| 973 | + * bar⏎ |
| 974 | +
|
| 975 | +which would result in the outer list incorrectly being marked loose with no |
| 976 | +trailing newline. (This may seem obvious, but we previously got this wrong; see |
| 977 | +GitHub issue #5.) |
| 978 | +
|
962 | 979 | One might wonder whether it’s safe to only do this transferring to immediately-
|
963 | 980 | enclosing lists, as there could be a blockquote in the way:
|
964 | 981 |
|
|
0 commit comments