Repository: getnikola/nikola

Issue:
Support for Pandoc-flavored markdown?
Hi all. I'm hoping to switch to using Nikola, but it appears to me that Pandoc-flavored markdown is not supported? Pandoc-flavored markdown is a super-set of other markdown flavors that provides some killer features not available elsewhere; the primary one being citation support. It would be wonderful to have this feature in Nikola. 



Discussion:
You can use it, if it has a file extension associated with it. We use:

pandoc -i posts/foo.md cache/foo.html

where .md is the file extension of choice. If this is enough to trigger
pandoc-flavored markdown, all is well. If you need some extra format
parameter, we would need to add support for that.

## So: what is the current situation?

Chris Warrick https://chriswarrick.com/
Sent from my Galaxy S3.
On Nov 16, 2014 7:30 PM, "Tamas Nagy" notifications@github.com wrote:

> Hi all. I'm hoping to switch to using Nikola, but it appears to me that
> Pandoc-flavored markdown is not supported? Pandoc-flavored markdown is a
> super-set of other markdown flavors that provides some killer features not
> available elsewhere; the primary one being citation support. It would be
> wonderful to have this feature in Nikola.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/getnikola/nikola/issues/1492.

Ah. The command needs to include `-F pandoc-citeproc` for citation processing. Also, you have to specify the location of the bibliography file (e.g. references.bib), though this can be done via included YAML inside the post (pandoc-citeproc does not error out if no bibliography is specified).

That is harder to implement globally and needs a special modified pandoc plugin.  Something we can’t easily do in the core, I’m afraid.

(Also, it’s not YAML.  It’s a proprietary format devised by us.)

So how would you recommend that I approach this? I could use pandoc to convert from pandoc markdown to restricted markdown and then run that through Nikola, but that seems redundant esp. since pandoc support is there, just limited.

@tinagy as a momentary workaround, you can edit pandoc.py and change the command line as you wish. Here's what it looks like now:

```
subprocess.check_call(('pandoc', '-o', dest, source))
```

You can just change it in the obvious way.

Additionally, we could support a PANDOC_OPTIONS in conf.py that sets options for pandoc, it's not horribly hard, and I can do it, if you think that's a good solution.

I think have a PANDOC_OPTIONS variable in conf.py would be nice. I could pass the location of a global references file via that option to pandoc and should be work fine. I modified that line you mentioned to:

```
            subprocess.check_call(('pandoc', '-o', dest, source, '-F',
                'pandoc-citeproc',
                '--bibliography=/Users/tamasnagy/references.bib'))
```

and it did what I wanted it to.

@tinagy how does using a pandoc pref file look like? I could just make it use .pandocrc in the site folder and we avoid yet another option.

I solved this by switching to the two-file mode (separate metadata and text) and doing Pandoc outside of Nikola. Files that require Pandoc are placed in "posts" or "stories" as HTML.

See http://znmeb.bitbucket.org/stories/blogging-with-rstudio-and-nikola.html


Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -345,6 +345,7 @@ def __init__(self, **config):
             'OUTPUT_FOLDER': 'output',
             'POSTS': (("posts/*.txt", "posts", "post.tmpl"),),
             'PAGES': (("stories/*.txt", "stories", "story.tmpl"),),
+            'PANDOC_OPTIONS': [],
             'PRETTY_URLS': False,
             'FUTURE_IS_NOW': False,
             'INDEX_READ_MORE_LINK': DEFAULT_INDEX_READ_MORE_LINK,
diff --git a/nikola/plugins/compile/pandoc.py b/nikola/plugins/compile/pandoc.py
--- a/nikola/plugins/compile/pandoc.py
+++ b/nikola/plugins/compile/pandoc.py
@@ -48,7 +48,7 @@ class CompilePandoc(PageCompiler):
     def compile_html(self, source, dest, is_two_file=True):
         makedirs(os.path.dirname(dest))
         try:
-            subprocess.check_call(('pandoc', '-o', dest, source))
+            subprocess.check_call(['pandoc', '-o', dest, source] + self.site.config['PANDOC_OPTIONS'])
         except OSError as e:
             if e.strreror == 'No such file or directory':
                 req_missing(['pandoc'], 'build this site (compile with pandoc)', python=False)


Test patch: