Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML metadata causes line number offset for sourcepos #7863

Closed
gpoore opened this issue Jan 24, 2022 · 0 comments
Closed

YAML metadata causes line number offset for sourcepos #7863

gpoore opened this issue Jan 24, 2022 · 0 comments
Labels

Comments

@gpoore
Copy link

gpoore commented Jan 24, 2022

sourcepos line numbers don't correspond to file line numbers when there is YAML metadata. Metadata introduces an offset equal to the number of lines of YAML plus any whitespace lines that follow.

This is for pandoc.exe 2.17.0.1.

Example file preview_test.md:

Text

Output of pandoc -f commonmark_x+sourcepos -t native -s ./preview_test.md:

Pandoc
  Meta { unMeta = fromList [] }
  [ Div
      ( ""
      , []
      , [ ( "data-pos" , "./preview_test.md@1:1-2:1" ) ]
      )
      [ Para
          [ Span
              ( ""
              , []
              , [ ( "data-pos" , "./preview_test.md@1:1-1:5" ) ]
              )
              [ Str "Text" ]
          ]
      ]
  ]

Modified example:

---
key:
  |
  value
...


Text

Modified output:

Pandoc
  Meta
    { unMeta =
        fromList [ ( "key" , MetaBlocks [ Para [ Str "value" ] ] ) ]
    }
  [ Div
      ( ""
      , []
      , [ ( "data-pos" , "./preview_test.md@1:1-2:1" ) ]
      )
      [ Para
          [ Span
              ( ""
              , []
              , [ ( "data-pos" , "./preview_test.md@1:1-1:5" ) ]
              )
              [ Str "Text" ]
          ]
      ]
  ]

I'm working on a commonmark_x preview extension for VS Code, and so far this has been the only thing interfering with scroll sync between Markdown source and HTML preview. It's possible to try to work around this for now by searching for the ending --- or ... to calculate the offset manually.

@gpoore gpoore added the bug label Jan 24, 2022
@jgm jgm closed this as completed in a9f901c Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant