Feature request: preserve source line numbers in AST nodes

Open
#64 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
clojure, java
Domain
tooling

Research direction

Start at the md/parse entry point and trace how the underlying commonmark-java parser's SourceSpans are handled, since the issue says this information is currently discarded. Determine how source positions should be represented on AST nodes, then verify that parsed nodes expose line information usable by linting tools.

Written by the indexing model from the issue text.

Description

Summary

It would be helpful if the parsed AST nodes included source line number information from the original markdown text.

Use case

When building linting tools that check markdown structure (e.g., heading hierarchy validation), error messages are much more useful when they can reference the specific line number:

Line 15: H1 not allowed in blog posts: 'Introduction'

vs just:

H1 not allowed in blog posts: 'Introduction'

Current behavior

The AST nodes only contain content, not source positions:

(require '[nextjournal.markdown :as md])
(md/parse "## Heading\n\nParagraph")
;; => {:content [{:type :heading, :heading-level 2, :content [...], :attrs {...}}
;;               {:type :paragraph, :content [...]}], ...}

Proposed behavior

Include source position information, perhaps as metadata or additional keys:

{:type :heading
 :heading-level 2
 :content [...]
 :attrs {...}
 :source {:line 1 :column 0}}  ;; or similar

Notes

The underlying commonmark-java parser does track source spans (SourceSpans), so this information is available during parsing but currently discarded.

Dominant language
Clojure
Stars
100
Forks
11
Avg merge
2h 3m
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nextjournal/markdown

All issues in nextjournal/markdown

Similar issues

More Clojure issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.