nextjournal 2026-07-17

hi! i'm interested in adding source spans to nextjournal. is that something you'd be interested in?

brief sketch of my approach: • spans are opt-in with {:source-spans? true}; they're supported with the commonmark parser but not in CLJS. markdown-it supports block line ranges but not sub-line ranges; if we had to support that things would be much harder. • each node gets a list of spans under :spans, mostly inherited from the Java commonmark parser:

[{:line 0
  :column 4
  :index 4
  :length 4
  :inherited? true}]
this has to be a list because spans are allowed to be disjoint (e.g. in a blockquote, it won't include the leading > in each span) • set :inherited? for "synthetic" nodes, such as created by :handlers. in the future this could be extended to allow the tokenizer to set its own spans. • omit :spans if the parser doesn't give us any spans back (could also be an empty list) • parse* only supports spans on the first call; it throws on subsequent pushback calls • :doc-handlers receive :spans as an input; they're responsible for attaching the spans to the nodes they create