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

Support YAML metadata block in gfm #6537

Closed
abitrolly opened this issue Jul 16, 2020 · 10 comments
Closed

Support YAML metadata block in gfm #6537

abitrolly opened this issue Jul 16, 2020 · 10 comments

Comments

@abitrolly
Copy link

abitrolly commented Jul 16, 2020

As explained in #2827 (comment) the gfm format specifier doesn't support YAML metadata blocks. This doesn't work currently.

pandoc mwe.md -f gfm+yaml_metadata_block -o mwe.pdf

The workaround for now is to use deprecated markdown_github format specifier.

pandoc mwe.md -f markdown_github+yaml_metadata_block -o mwe.pdf
✗ pandoc -v
pandoc 2.7.3
Compiled with pandoc-types 1.17.6.1, texmath 0.11.3, skylighting 0.8.2.1
Default user data directory: /home/anatoli/.local/share/pandoc or /home/anatoli/.pandoc
Copyright (C) 2006-2019 John MacFarlane
Web:  http://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.
@craigbarnes
Copy link

craigbarnes commented Dec 18, 2020

GitHub has had special rendering for YAML metadata in Markdown for a few years now, so it might make sense to support YAML blocks even when just using -f gfm.

@caressofsteel
Copy link

I can't think of any good reason not to support this. I wasted an hour or two trying to figure out why the YAML was being spit as part of the PDF before I stumbled upon the workaround.

@tarleb
Copy link
Collaborator

tarleb commented Feb 13, 2021 via email

@abitrolly
Copy link
Author

@taleb so the task is to find the code for yaml_metadata_block and merge it into gfm to make it the default behavior? Or the task is to fix behavior of compound format specifier gfm+yaml_metadata_block?

@tarleb
Copy link
Collaborator

tarleb commented Feb 14, 2021

GitHub Flavored Markdown is a variant of CommonMark and pandoc uses the commonmark-hs library for parsing it. The challenge is to add YAML support there. The repo is https://github.com/jgm/commonmark-hs.

@tarleb
Copy link
Collaborator

tarleb commented Feb 14, 2021

See also jgm/commonmark-hs#17

@jgm
Copy link
Owner

jgm commented Feb 15, 2021

This is a bit more complicated than the average commonmark extension, because here we need to parse the YAML into a YAML object, and then parse the terminal nodes as commonmark. I have to think about the best way to handle this.

@shiftybit
Copy link

In the mean time, is there any way to hide the metadata block from the output? For my purposes, just discarding it is fine.

@jgm
Copy link
Owner

jgm commented Feb 25, 2021

Your best bet is probably to preprocess the input and strip it off before passing to pandoc.
An alternative approach would be to use pandoc's markdown instead of gfm as your input format.

@shiftybit
Copy link

shiftybit commented Feb 25, 2021

Ended up doing this. --- worked out to return as horizontal rule, so for my needs, I just sort of modified one of the example scripts.

from pandocfilters import toJSONFilter
incomment = False
firstLine = True

def comment(k, v, fmt, meta):
	global incomment
	global firstLine
	if(firstLine and k == 'HorizontalRule'):
		incomment = True
		firstLine = False
		return []
	elif(incomment and k == 'HorizontalRule'):
		incomment = False
		return []

	if incomment:
		return []  # suppress anything in a header

if __name__ == "__main__":
	toJSONFilter(comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants