Is there a way for maked 2 to read de YAML block with pandoc and not ask for a .csl and .bib file
Hi!
I was using standard pandoc without any type of preview and when I converted the file using pandoc, it recognizes that I am trying using a reference file and a csl file because I specified it at the top inside the YAML block. So I didn't need to provide the usual --biblioraphy= and --csl commands.
When previewing with marked 2 is there a way to accomplish it? Every time I am changing from project to project I need to provide the full path, instead of taking it from the YAML block.
I hope I made myself clear.
Thank you.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Brett on 22 May, 2021 07:00 PM
Just so I understand, are you using Pandoc as the custom processor
within Marked?
The issue you're likely running into is that when Marked calls out to a
custom processor, it's just passing the contents of the file, not the
file itself. That means that if you use a relative path in the headers,
Pandoc has no way of knowing what it's relative to. It would be possible
to use a custom preprocessor to change the YAML header to include an
absolute path based on the main file's location, but I'd have to see
exactly what your setup is to know if that would help.
-Brett
2 Posted by Jvet on 23 May, 2021 12:29 AM
Yes I’m using pandoc as the preprocessor and I have no problem working with it using the standard pandoc commands.
The text editor I use is atom, the YAML for example:
——— Title: markdown
Author: me
Bibliography: mdb.bib
Citation style: vnc.cal
———
The .bib file and the .csl are inside the same folder as the .md I’m working on. I used to work with a package that allowed me to preview also using pandoc and it was capable of rendering the html with formatted citations and bibliography just with the information from the YAML.
So I was wondering if there’s a way to do that with marked or is it necessary to always provide the arguments —csl and —bibliography. This because I prefer to use marked 2 due to the extensive functionality and export options.
I hope I provided the information you needed.
Support Staff 3 Posted by Brett on 23 May, 2021 07:39 PM
What I'm saying is that the relative paths in your YAML don't mean
anything to the custom processor, because it's passing input as if it
were pasted, not actually pointing to a file. Therefore Pandoc has no
way to know what the "md.bib" filename is relative TO, as it doesn't
know where the original file is.
Like I said, this could be worked around with a custom preprocessor
script. Preprocessors have environment variables available that tell it
where the original file was located and could scan for "Bibliography:"
lines and replace the filename with an absolute path. I think that would
fix it. I'm happy to help write one, if you need a hand.
-Brett
4 Posted by Jvet on 24 May, 2021 12:22 AM
That would be great because I’m really not very tech savvy.
Support Staff 5 Posted by Brett on 24 May, 2021 11:32 AM
I'll give it a shot, but FYI I just started a new day job and I might
not have time to get to it right away.
Thanks,
Brett
6 Posted by Jvet on 24 May, 2021 02:42 PM
No problem! I appreciate you take the time to help :)
Support Staff 7 Posted by Brett on 25 May, 2021 06:54 PM
All right, here's one that should work. I'll detail these instructions as if you have no idea what you're doing, so bear with me if it all seems obvious.
You can put the script anywhere, but for the purposes of these instructions, let's create a folder in your home folder called "scripts".
Save the text below to a plain text file called
citationpre.rb
in the scripts folder. If doing this with something like TextEdit, make sure it's in Plain Text mode, not Rich Text.Open Terminal and run this command to make the file executable (modifying the path if you didn't use ~/scripts):
chmod a+x ~/scripts/citationpre.rb
.In Marked's Preferences go to the Advanced tab and switch to the Custom Preprocessor view. Enable it, and enter
~/scripts/citationpre.rb
as the Path (it will expand it to a full path when you tab out of the field). Leave Args blank, and check "Automatically enable for new windows."Test it out by opening a file containing the proper YAML as you showed me above. The script outputs some debug messages to STDERR, so if you enable Debug Mode in Advanced Preferences, you can use Help->Show Custom Processor Log to view them.
Here's the script. It looks for lines starting with "Bibliography:" or "Citation style:" and ending with either
.bib
or.cal
. It should replace a filename likemdb.bib
with/Users/yourname/path/to/mdb.bib
, assuming it's in the same folder as the file you're previewing. Because it's running as a preprocessor, this change should happen before the text gets sent to Pandoc for rendering. Hopefully that allows Pandoc to resolve the paths and render the citations properly.Let me know how it goes.