Skip to content

Setext heading's end position is on the line after its underline #659

Open

Description

@tsnee

With --sourcepos, a setext heading that isn't at the end of the document gets an end position on the line after its underline, which belongs to the next block (or is blank).

Reproduced on cmark 0.31.2 (Homebrew, macOS) and on master at d56b4bd.

Input (g.md):

Foo
---
bar

cmark --sourcepos -t xml g.md (excerpt):

<heading sourcepos="1:1-3:3" level="2">
<paragraph sourcepos="3:1-3:3">

The heading ends at 3:3, the end of the paragraph's line, overlapping the paragraph.

With a blank line after the underline (h.md):

Foo
---

bar

cmark --sourcepos -t xml h.md (excerpt):

<heading sourcepos="1:1-3:0" level="2">
<paragraph sourcepos="4:1-4:3">

The heading ends at 3:0, column 0 of the blank line, which isn't a position of any character.

At the end of the document it's right: Foo\n---\n gives 1:1-2:3.

Expected 1:1-2:3 in all three cases: the underline's line and last column. commonmark.js 0.31.2 gives [[1,1],[2,3]] for both g.md and h.md, and commonmark-java 0.31.0 gives source spans on lines 1 and 2 only.

Not the same as #141 (whether the underline is included at all, which it is, as expected) or #296 (inline positions). Possibly related: #656, another heading whose end position is wrong (an empty ATX heading's ends before its start).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions