Is there a way for maked 2 to read de YAML block with pandoc and not ask for a .csl and .bib file

Jvet's Avatar


22 May, 2021 06:17 PM


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.

  1. Support Staff 1 Posted by Brett on 22 May, 2021 07:00 PM

    Brett's Avatar

    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.


  2. 2 Posted by Jvet on 23 May, 2021 12:29 AM

    Jvet's Avatar

    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:

    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.

  3. Support Staff 3 Posted by Brett on 23 May, 2021 07:39 PM

    Brett's Avatar

    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.


  4. 4 Posted by Jvet on 24 May, 2021 12:22 AM

    Jvet's Avatar

    That would be great because I’m really not very tech savvy.

  5. Support Staff 5 Posted by Brett on 24 May, 2021 11:32 AM

    Brett's Avatar

    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.


  6. 6 Posted by Jvet on 24 May, 2021 02:42 PM

    Jvet's Avatar

    No problem! I appreciate you take the time to help :)

  7. Support Staff 7 Posted by Brett on 25 May, 2021 06:54 PM

    Brett's Avatar

    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".

    1. 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.

    2. 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.

    3. 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."

    4. 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 like mdb.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.

    #!/usr/bin/env ruby
    input = $
    base = File.dirname(ENV['MARKED_PATH'])
    print input.gsub(/^((?:Bibliography|Citation style): )(.*?\.(?:bib|cal))$/i) {|f|
      m = Regexp.last_match
      $stderr.puts "Matched #{m[0]}, expanding to #{File.join(base, m[2].strip)}"
      "#{m[1]}#{File.join(base, m[2].strip)}"

    Let me know how it goes.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? 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