tag:support.markedapp.com,2011-09-11:/discussions/questions/10628-is-there-a-way-for-maked-2-to-read-de-yaml-block-with-pandoc-and-not-ask-for-a-csl-and-bib-fileMarked: Discussion 2021-05-25T18:54:22Ztag:support.markedapp.com,2011-09-11:Comment/492103862021-05-22T19:00:59Z2021-05-22T19:00:59ZIs there a way for maked 2 to read de YAML block with pandoc and not ask for a .csl and .bib file<div><p>Just so I understand, are you using Pandoc as the custom processor<br>
within Marked?</p>
<p>The issue you're likely running into is that when Marked calls out to a<br>
custom processor, it's just passing the contents of the file, not the<br>
file itself. That means that if you use a relative path in the headers,<br>
Pandoc has no way of knowing what it's relative to. It would be possible<br>
to use a custom preprocessor to change the YAML header to include an<br>
absolute path based on the main file's location, but I'd have to see<br>
exactly what your setup is to know if that would help.</p>
<p>-Brett</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/492103862021-05-23T00:29:23Z2021-05-23T00:29:23ZIs there a way for maked 2 to read de YAML block with pandoc and not ask for a .csl and .bib file<div><p>Yes I’m using pandoc as the preprocessor and I have no problem working with it using the standard pandoc commands.</p>
<p>The text editor I use is atom, the YAML for example:</p>
<p>——— Title: markdown<br>
Author: me<br>
Bibliography: mdb.bib<br>
Citation style: vnc.cal<br>
———</p>
<p>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.</p>
<p>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.</p>
<p>I hope I provided the information you needed.</p></div>Jvettag:support.markedapp.com,2011-09-11:Comment/492103862021-05-23T19:39:45Z2021-05-23T19:39:45ZIs there a way for maked 2 to read de YAML block with pandoc and not ask for a .csl and .bib file<div><p>What I'm saying is that the relative paths in your YAML don't mean<br>
anything to the custom processor, because it's passing input as if it<br>
were pasted, not actually pointing to a file. Therefore Pandoc has no<br>
way to know what the "md.bib" filename is relative TO, as it doesn't<br>
know where the original file is.</p>
<p>Like I said, this could be worked around with a custom preprocessor<br>
script. Preprocessors have environment variables available that tell it<br>
where the original file was located and could scan for "Bibliography:"<br>
lines and replace the filename with an absolute path. I think that would<br>
fix it. I'm happy to help write one, if you need a hand.</p>
<p>-Brett</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/492103862021-05-24T00:22:08Z2021-05-24T00:22:08ZIs there a way for maked 2 to read de YAML block with pandoc and not ask for a .csl and .bib file<div><p>That would be great because I’m really not very tech savvy.</p></div>Jvettag:support.markedapp.com,2011-09-11:Comment/492103862021-05-24T11:32:40Z2021-05-24T11:32:40ZIs there a way for maked 2 to read de YAML block with pandoc and not ask for a .csl and .bib file<div><p>I'll give it a shot, but FYI I just started a new day job and I might<br>
not have time to get to it right away.</p>
<p>Thanks,<br>
Brett</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/492103862021-05-24T14:42:24Z2021-05-24T14:42:24ZIs there a way for maked 2 to read de YAML block with pandoc and not ask for a .csl and .bib file<div><p>No problem! I appreciate you take the time to help :)</p></div>Jvettag:support.markedapp.com,2011-09-11:Comment/492103862021-05-25T18:54:22Z2021-05-25T18:54:22ZIs there a way for maked 2 to read de YAML block with pandoc and not ask for a .csl and .bib file<div><p>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.</p>
<p>You can put the script anywhere, but for the purposes of these instructions, let's create a folder in your home folder called "scripts".</p>
<ol>
<li>
<p>Save the text below to a plain text file called <code>citationpre.rb</code> in the scripts folder. If doing this with something like TextEdit, make sure it's in Plain Text mode, not Rich Text.</p>
</li>
<li>
<p>Open Terminal and run this command to make the file executable (modifying the path if you didn't use ~/scripts): <code>chmod a+x ~/scripts/citationpre.rb</code>.</p>
</li>
<li>
<p>In Marked's Preferences go to the Advanced tab and switch to the Custom Preprocessor view. Enable it, and enter <code>~/scripts/citationpre.rb</code> 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."</p>
</li>
<li>
<p>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.</p>
</li>
</ol>
<p>Here's the script. It looks for lines starting with "Bibliography:" or "Citation style:" and ending with either <code>.bib</code> or <code>.cal</code>. It should replace a filename like <code>mdb.bib</code> with <code>/Users/yourname/path/to/mdb.bib</code>, 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.</p>
<pre>
<code>#!/usr/bin/env ruby
input = $stdin.read
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)}"
}</code>
</pre>
<p>Let me know how it goes.</p></div>Brett