|
195 | 195 | should-close? (assoc :indent-code-end true))]
|
196 | 196 | [text state])))))
|
197 | 197 |
|
198 |
| -(defn codeblock [text {:keys [codeblock codeblock-end indented-code next-line lists] :as state}] |
| 198 | +(defn codeblock [text {:keys [codeblock-buf codeblock-lang codeblock-callback codeblock codeblock-end indented-code next-line lists] :as state}] |
199 | 199 | (let [trimmed (string/trim text)
|
200 | 200 | next-line-closes? (some-> next-line string/trim (string/ends-with? "```"))]
|
201 | 201 | (cond
|
202 | 202 | (and lists codeblock-end)
|
203 |
| - ["" (dissoc state :code :codeblock :codeblock-end)] |
| 203 | + ["" (dissoc state :code :codeblock :codeblock-end :codeblock-lang :codeblock-buf)] |
204 | 204 |
|
205 | 205 | codeblock-end
|
206 | 206 | [text (-> state
|
207 | 207 | (assoc :last-line-empty? true)
|
208 |
| - (dissoc :code :codeblock :codeblock-end))] |
| 208 | + (dissoc :code :codeblock :codeblock-end :codeblock-lang :codeblock-buf))] |
209 | 209 |
|
210 | 210 | (and next-line-closes? codeblock)
|
211 |
| - [(str (escape-code (str text \newline (apply str (first (string/split next-line #"```"))))) "</code></pre>") |
212 |
| - (assoc state :skip-next-line? (not lists) |
213 |
| - :codeblock-end true |
214 |
| - :last-line-empty? (not lists))] |
| 211 | + (let [buffered-code (str codeblock-buf text)] |
| 212 | + [(str (escape-code (str (if codeblock-callback (codeblock-callback buffered-code codeblock-lang) buffered-code) \newline (apply str (first (string/split next-line #"```"))))) "</code></pre>") |
| 213 | + (assoc state :skip-next-line? (not lists) |
| 214 | + :codeblock-end true |
| 215 | + :last-line-empty? (not lists))]) |
215 | 216 |
|
216 | 217 | (and
|
217 | 218 | (not indented-code)
|
|
229 | 230 | (when next-line-closes? "</code></pre>"))
|
230 | 231 | (if next-line-closes?
|
231 | 232 | (assoc state :codeblock-end true :skip-next-line? true)
|
232 |
| - (assoc state :code true :codeblock true))]) |
| 233 | + (assoc state :code true |
| 234 | + :codeblock true |
| 235 | + :codeblock-lang lang |
| 236 | + :codeblock-buf ""))]) |
233 | 237 |
|
234 | 238 | codeblock
|
235 |
| - [(str (escape-code text) "\n") state] |
| 239 | + ["" (assoc state :codeblock-buf (str codeblock-buf text \newline))] |
236 | 240 |
|
237 | 241 | :default
|
238 | 242 | [text state])))
|
|
0 commit comments