|
15 | 15 | ) |
16 | 16 | ) |
17 | 17 |
|
18 | | -;;; Sidenotes are a complete hairy mess, see logseq://graph/doc?page=sidenotes |
19 | | - |
20 | 18 | ;;; Turn parsed content into hiccup. |
21 | 19 |
|
22 | 20 | (declare block-content->hiccup) ;allow recursion on this |
|
200 | 198 |
|
201 | 199 | (declare block-hiccup) |
202 | 200 |
|
203 | | -;;; Blocks used as sidenotes get recorded here so they skip their normal render |
204 | | -;;; Yes this is global state and bad practice. Shoot me. |
205 | | -;;; TODO should get reset like u/memoizers |
206 | | -(def sidenotes (atom #{})) |
207 | | - |
208 | | -(defn sidenote? |
209 | | - [id] |
210 | | - (contains? @sidenotes id)) |
211 | 201 |
|
212 | | -;;; TODO flush all this kludgey machinery, new way is much simpler. Need to convert existing files |
213 | | -;;; This is used to suppress sidenotes in the Incoming links panel |
214 | | -;;; TODO now misnamed, we now just supress RENDERING them as sidenotes, still want them |
215 | | -(def ^{:dynamic true} *no-sidenotes* false) |
216 | | - |
217 | | -;;; Render a sidenote (and both *s) |
218 | | -(defn sidenote |
219 | | - [block-map sidenote-block] |
220 | | - (swap! sidenotes conj (:id sidenote-block)) |
221 | | - [:span.sidenote-container |
222 | | - [:span.superscript] |
223 | | - [:div.sidenote ;TODO option to render on left/right |
224 | | - [:span.superscript.side] |
225 | | - (block-full-hiccup-guts (:id sidenote-block) block-map)]]) |
226 | 202 |
|
227 | 203 |
|
228 | 204 | ;;; A much easier way to do sidenotes |
|
335 | 311 | :block-ref (let [ref-block (get (uid-indexed block-map) (-> ele-content |
336 | 312 | str/trim |
337 | 313 | utils/remove-double-delimiters))] |
338 | | - (try |
339 | | - ;; :block-ref is repurposed for sidenotes, see doc |
340 | | - (if (and block |
341 | | - (= (bd/block-page block-map ref-block) ;if ref and block are on the same page |
342 | | - (bd/block-page block-map block))) |
343 | | - (when-not *no-sidenotes* |
344 | | - (sidenote block-map ref-block)) ;render the sidenote |
345 | 314 | [:div.block-ref ;render a real blockref |
346 | 315 | (block-hiccup ref-block block-map)]) |
347 | | - ;; Specifically, bad block refs will cause this. |
348 | | - (catch Throwable e |
349 | | - [:div.error "Couldn't render: " (str ast-ele)]))) |
350 | 316 | :hashtag (let [ht (utils/parse-hashtag ele-content)] |
351 | 317 | (or (bd/special-hashtag-handler block-map ht block) |
352 | 318 | (page-link-by-name block-map ht))) |
|
399 | 365 | parsed)) |
400 | 366 |
|
401 | 367 | ;;; In lieu of putting this in the blockmap |
402 | | -;;; TODO memoization runs into *no-sidenotes* dynamic variable I think. So turned off. Shouldn't be calling this too many times I think? |
403 | 368 | ;;; TODO turn it back on with old sidenote feature is history |
404 | 369 | (defn block-hiccup |
405 | 370 | "Convert Roam markup to Hiccup" |
|
444 | 409 | (map #(block-full-hiccup % block-map (inc depth)) |
445 | 410 | (:children block))]))) |
446 | 411 |
|
447 | | -(defn sidenote? |
448 | | - [id] |
449 | | - (contains? @sidenotes id)) |
450 | | - |
451 | 412 | ;;; The real top-level call |
452 | 413 | (defn block-full-hiccup |
453 | 414 | [block-id block-map & [depth]] |
454 | | - ;; This logic is very squirelly...we want sidenote blocks to render normally when they are in the linked-ref pane |
455 | | - (when (or *no-sidenotes* (not (sidenote? block-id))) |
456 | | - (block-full-hiccup-guts block-id block-map depth))) |
457 | | - |
458 | | -(defn block-full-hiccup-no-sidenotes |
459 | | - [& args] |
460 | | - (binding [*no-sidenotes* true] |
461 | | - (apply block-full-hiccup args))) |
| 415 | + (block-full-hiccup-guts block-id block-map depth)) |
462 | 416 |
|
463 | 417 | (defn page-hiccup |
464 | 418 | [block-id block-map] |
|
0 commit comments