Skip to content

Position tracking of headings is inconsistent #141

Closed

Description

@neongreen

The following demonstration uses Haskell bindings for cmark (unfortunately, I don't know C so I'm unable to port the example to C; I assume the bindings are faithful and don't mess anything up).

Position info for a #-style header doesn't include the # (i.e. it starts from column 3 instead of column 1):

> let Node _ DOCUMENT [n] = commonmarkToNode [] (T.pack "# hello") in n

Node (Just (PosInfo {startLine = 1, 
                     startColumn = 3, 
                     endLine = 1, 
                     endColumn = 7})) 
     (HEADING 1) 
     [Node Nothing (TEXT "hello") []]

Position info for a =====-style header does include the ===== (i.e. it ends at line 2, not line 1):

> let Node _ DOCUMENT [n] = commonmarkToNode [] (T.pack "hello\n=====") in n

Node (Just (PosInfo {startLine = 1, 
                     startColumn = 1,
                     endLine = 2,
                     endColumn = 5})) 
     (HEADING 1)
     [Node Nothing (TEXT "hello") []]

The latter behavior seems more correct to me and it'd be good if source positions for #-style headers behaved the same way.

Activity

  1. jgm commented on Jul 7, 2016

    @jgm
    Member

    +++ Artyom [Jul 07 16 14:38 ]:

    The following demonstration uses Haskell bindings for cmark
    (unfortunately, I don't know C so I'm unable to port the example to C;

    You can do

    cmark -t xml --sourcepos
    

    to see what source positions the C library is assigning.

  2. neongreen commented on Jul 7, 2016

    @neongreen
    ContributorAuthor

    Thanks!

    I built cmark (from Github) and fed it the following file:

    # foo
    
    bar
    ===
    

    It produced the following output (which exhibits the same behavior as my original Haskell demonstration):

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE document SYSTEM "CommonMark.dtd">
    <document sourcepos="1:1-4:3" xmlns="http://commonmark.org/xml/1.0">
      <heading sourcepos="1:3-1:5" level="1">
        <text>foo</text>
      </heading>
      <heading sourcepos="3:1-4:3" level="1">
        <text>bar</text>
      </heading>
    </document>
  3. changed the title [-]Position tracking of headers is inconsistent[/-] [+]Position tracking of headings is inconsistent[/+] on Jul 8, 2016
  4. added a commit that references this issue on Feb 1, 2024
    005d6d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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