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

No newline at end of metadata file causes misparsing of raw block #9128

Closed
iandol opened this issue Oct 11, 2023 · 4 comments
Closed

No newline at end of metadata file causes misparsing of raw block #9128

iandol opened this issue Oct 11, 2023 · 4 comments
Labels

Comments

@iandol
Copy link
Contributor

iandol commented Oct 11, 2023

Explain the problem.

See https://groups.google.com/g/pandoc-discuss/c/FT_hz4lbNnA for context.

Use this metadata file (I tested with backticks but this causes problems in github so here I replace backticks with tildes; make sure no newline after end of raw block):

header-includes: |
  ~~~{=typst}
  #set heading(numbering: "«I»")
  #set text(font: "Alegreya Sans", size: 14pt, discretionary-ligatures: true, number-type: "old-style")
  ~~~

Now call pandoc with this file (type something into STDIN)

pandoc -s --metadata-file test.yaml -t typst --verbose
# Title

Some text.

[CTRL+D]

output...

`{=typst} #set heading(numbering: "«I»") #set text(font: "Alegreya Sans", size: 14pt, discretionary-ligatures: true, number-type: "old-style")`

= Title
<title>
Some text.

Note the header-include is malformed. Now add a newline in the metadata file:

header-includes: |
  ~~~{=typst}
  #set heading(numbering: "«I»")
  #set text(font: "Alegreya Sans", size: 14pt, discretionary-ligatures: true, number-type: "old-style")
  ~~~
  

And now the raw block gets output properly:

    #set heading(numbering: "«I»")
    #set text(font: "Alegreya Sans", size: 14pt, discretionary-ligatures: true, number-type: "old-style")
    
    
    = Title
    <title>
    Some text.

Honestly, I don't understand the YAML spec well enough to know if this is expected or not:

https://yaml.org/spec/1.2.2/#812-literal-style

The default block chomping is apparently clip: https://yaml.org/spec/1.2.2/#8112-block-chomping-indicator — but any setting (e.g. +) doesn't impact this behaviour in Pandoc...

@iandol iandol added the bug label Oct 11, 2023
@jgm
Copy link
Owner

jgm commented Oct 11, 2023

Oh, I see -- you had a text file that didn't end in a newline?

@iandol
Copy link
Contributor Author

iandol commented Oct 11, 2023

Yes, I ended up with a separate metadata file as I couldn't get the header-includes to work added to the defaults file directly. Note if it is a raw inline then it works:

header-includes: |
  `#set heading(numbering: "«I»")`{=typst}

Test:

▷ pandoc -s --metadata-file test.yaml -t typst --verbose
# Title

Some text.

[CTRL+D]

...

#set heading(numbering: "«I»")


= Title
<title>
Some text.

So the lack of newline only affects raw blocks not raw inlines (which makes some sense).

@jgm
Copy link
Owner

jgm commented Oct 11, 2023

Text files canonically are supposed to end with a newline; lots of things break if they don't.

@iandol
Copy link
Contributor Author

iandol commented Oct 12, 2023

Ok, as this is already a bit of an edge case, I'll close it...

@iandol iandol closed this as completed Oct 12, 2023
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

2 participants