We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
dispatch PANDOC_OPTIONS base on input extensions
<!--
Before creating an issue:
* make sure you are using an up-to-date version of Nikola
* search for existing issues that might be related

Describe your requested features as precisely as possible. -->

# Summary

Currently, `COMPILERS` only has a key `pandoc`, and `PANDOC_OPTIONS` is set for all the extensions specified there. The proposed feature simply suggests to have configurable dispatch logic to allow multiple extensions calling pandoc with a different set of `PANDOC_OPTIONS`.

# Example use case

My personal use for this would be to convert one of my site currently using `.md` and `.markdown` to mean a different target format. Both will be converted to HTML, but one of them is slideshow, another is normal "article"/post.

Another possible use case is, if one want to specify markdown extensions in pandoc, say `-t markdown+...-...`, then `COMPILERS['pandoc'] = ['.rst', '.md']` won't work with `PANDOC_OPTIONS = ['-t', 'markdown+...-...']` because that would be wrong input format for `.rst`.

# Suggested implementation

Probably the natural way is to promote

```py
PANDOC_OPTIONS: Union[list, Dict[str, list]]
```

where the keys are those in `COMPILERS['pandoc']`.

If it makes sense I can send a PR doing that. It seems that it only requires changes in <https://github.com/getnikola/nikola/blob/master/nikola/plugins/compile/pandoc.py#L52-L56>, is it true?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `nikola/plugins/compile/pandoc.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 # Copyright © 2012-2021 Roberto Alsina and others.
4 
5 # Permission is hereby granted, free of charge, to any
6 # person obtaining a copy of this software and associated
7 # documentation files (the "Software"), to deal in the
8 # Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the
11 # Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
13 #
14 # The above copyright notice and this permission notice
15 # shall be included in all copies or substantial portions of
16 # the Software.
17 #
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
22 # OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 
27 """Page compiler plugin for pandoc.
28 
29 You will need, of course, to install pandoc
30 """
31 
32 
33 import io
34 import os
35 import subprocess
36 
37 from nikola.plugin_categories import PageCompiler
38 from nikola.utils import req_missing, makedirs, write_metadata
39 
40 
41 class CompilePandoc(PageCompiler):
42     """Compile markups into HTML using pandoc."""
43 
44     name = "pandoc"
45     friendly_name = "pandoc"
46 
47     def set_site(self, site):
48         """Set Nikola site."""
49         self.config_dependencies = [str(site.config['PANDOC_OPTIONS'])]
50         super().set_site(site)
51 
52     def compile(self, source, dest, is_two_file=True, post=None, lang=None):
53         """Compile the source file into HTML and save as dest."""
54         makedirs(os.path.dirname(dest))
55         try:
56             subprocess.check_call(['pandoc', '-o', dest, source] + self.site.config['PANDOC_OPTIONS'])
57             with open(dest, 'r', encoding='utf-8-sig') as inf:
58                 output, shortcode_deps = self.site.apply_shortcodes(inf.read())
59             with open(dest, 'w', encoding='utf-8') as outf:
60                 outf.write(output)
61             if post is None:
62                 if shortcode_deps:
63                     self.logger.error(
64                         "Cannot save dependencies for post {0} (post unknown)",
65                         source)
66             else:
67                 post._depfile[dest] += shortcode_deps
68         except OSError as e:
69             if e.strreror == 'No such file or directory':
70                 req_missing(['pandoc'], 'build this site (compile with pandoc)', python=False)
71 
72     def compile_string(self, data, source_path=None, is_two_file=True, post=None, lang=None):
73         """Compile into HTML strings."""
74         raise ValueError("Pandoc compiler does not support compile_string due to multiple output formats")
75 
76     def create_post(self, path, **kw):
77         """Create a new post."""
78         content = kw.pop('content', None)
79         onefile = kw.pop('onefile', False)
80         # is_page is not used by create_post as of now.
81         kw.pop('is_page', False)
82         metadata = {}
83         metadata.update(self.default_metadata)
84         metadata.update(kw)
85         makedirs(os.path.dirname(path))
86         if not content.endswith('\n'):
87             content += '\n'
88         with io.open(path, "w+", encoding="utf8") as fd:
89             if onefile:
90                 fd.write(write_metadata(metadata, comment_wrap=True, site=self.site, compiler=self))
91             fd.write(content)
92
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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
@@ -33,6 +33,8 @@
 import io
 import os
 import subprocess
+from typing import List
+from pathlib import Path
 
 from nikola.plugin_categories import PageCompiler
 from nikola.utils import req_missing, makedirs, write_metadata
@@ -49,11 +51,30 @@
         self.config_dependencies = [str(site.config['PANDOC_OPTIONS'])]
         super().set_site(site)
 
+    def _get_pandoc_options(self, source: str) -> List[str]:
+        """Obtain pandoc args from config depending on type and file extensions."""
+        # Union[List[str], Dict[str, List[str]]]
+        config_options = self.site.config['PANDOC_OPTIONS']
+        type_ = type(config_options)
+        if type_ is list:
+            pandoc_options = config_options
+        elif type_ is dict:
+            ext = Path(source).suffix
+            try:
+                pandoc_options = config_options[ext]
+            except KeyError:
+                self.logger.warn('Setting PANDOC_OPTIONS to [], because extension {} is not defined in PANDOC_OPTIONS: {}.'.format(ext, config_options))
+                pandoc_options = []
+        else:
+            self.logger.warn('Setting PANDOC_OPTIONS to [], because PANDOC_OPTIONS is expected to be of type Union[List[str], Dict[str, List[str]]] but this is not: {}'.format(config_options))
+            pandoc_options = []
+        return pandoc_options
+
     def compile(self, source, dest, is_two_file=True, post=None, lang=None):
         """Compile the source file into HTML and save as dest."""
         makedirs(os.path.dirname(dest))
         try:
-            subprocess.check_call(['pandoc', '-o', dest, source] + self.site.config['PANDOC_OPTIONS'])
+            subprocess.check_call(['pandoc', '-o', dest, source] + self._get_pandoc_options(source))
             with open(dest, 'r', encoding='utf-8-sig') as inf:
                 output, shortcode_deps = self.site.apply_shortcodes(inf.read())
             with open(dest, 'w', encoding='utf-8') as outf:

{"golden_diff": "diff --git a/nikola/plugins/compile/pandoc.py b/nikola/plugins/compile/pandoc.py\n--- a/nikola/plugins/compile/pandoc.py\n+++ b/nikola/plugins/compile/pandoc.py\n@@ -33,6 +33,8 @@\n import io\n import os\n import subprocess\n+from typing import List\n+from pathlib import Path\n \n from nikola.plugin_categories import PageCompiler\n from nikola.utils import req_missing, makedirs, write_metadata\n@@ -49,11 +51,30 @@\n         self.config_dependencies = [str(site.config['PANDOC_OPTIONS'])]\n         super().set_site(site)\n \n+    def _get_pandoc_options(self, source: str) -> List[str]:\n+        \"\"\"Obtain pandoc args from config depending on type and file extensions.\"\"\"\n+        # Union[List[str], Dict[str, List[str]]]\n+        config_options = self.site.config['PANDOC_OPTIONS']\n+        type_ = type(config_options)\n+        if type_ is list:\n+            pandoc_options = config_options\n+        elif type_ is dict:\n+            ext = Path(source).suffix\n+            try:\n+                pandoc_options = config_options[ext]\n+            except KeyError:\n+                self.logger.warn('Setting PANDOC_OPTIONS to [], because extension {} is not defined in PANDOC_OPTIONS: {}.'.format(ext, config_options))\n+                pandoc_options = []\n+        else:\n+            self.logger.warn('Setting PANDOC_OPTIONS to [], because PANDOC_OPTIONS is expected to be of type Union[List[str], Dict[str, List[str]]] but this is not: {}'.format(config_options))\n+            pandoc_options = []\n+        return pandoc_options\n+\n     def compile(self, source, dest, is_two_file=True, post=None, lang=None):\n         \"\"\"Compile the source file into HTML and save as dest.\"\"\"\n         makedirs(os.path.dirname(dest))\n         try:\n-            subprocess.check_call(['pandoc', '-o', dest, source] + self.site.config['PANDOC_OPTIONS'])\n+            subprocess.check_call(['pandoc', '-o', dest, source] + self._get_pandoc_options(source))\n             with open(dest, 'r', encoding='utf-8-sig') as inf:\n                 output, shortcode_deps = self.site.apply_shortcodes(inf.read())\n             with open(dest, 'w', encoding='utf-8') as outf:\n", "issue": "dispatch PANDOC_OPTIONS base on input extensions\n<!--\r\nBefore creating an issue:\r\n* make sure you are using an up-to-date version of Nikola\r\n* search for existing issues that might be related\r\n\r\nDescribe your requested features as precisely as possible. -->\r\n\r\n# Summary\r\n\r\nCurrently, `COMPILERS` only has a key `pandoc`, and `PANDOC_OPTIONS` is set for all the extensions specified there. The proposed feature simply suggests to have configurable dispatch logic to allow multiple extensions calling pandoc with a different set of `PANDOC_OPTIONS`.\r\n\r\n# Example use case\r\n\r\nMy personal use for this would be to convert one of my site currently using `.md` and `.markdown` to mean a different target format. Both will be converted to HTML, but one of them is slideshow, another is normal \"article\"/post.\r\n\r\nAnother possible use case is, if one want to specify markdown extensions in pandoc, say `-t markdown+...-...`, then `COMPILERS['pandoc'] = ['.rst', '.md']` won't work with `PANDOC_OPTIONS = ['-t', 'markdown+...-...']` because that would be wrong input format for `.rst`.\r\n\r\n# Suggested implementation\r\n\r\nProbably the natural way is to promote\r\n\r\n```py\r\nPANDOC_OPTIONS: Union[list, Dict[str, list]]\r\n```\r\n\r\nwhere the keys are those in `COMPILERS['pandoc']`.\r\n\r\nIf it makes sense I can send a PR doing that. It seems that it only requires changes in <https://github.com/getnikola/nikola/blob/master/nikola/plugins/compile/pandoc.py#L52-L56>, is it true?\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Copyright \u00a9 2012-2021 Roberto Alsina and others.\n\n# Permission is hereby granted, free of charge, to any\n# person obtaining a copy of this software and associated\n# documentation files (the \"Software\"), to deal in the\n# Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish,\n# distribute, sublicense, and/or sell copies of the\n# Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice\n# shall be included in all copies or substantial portions of\n# the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY\n# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR\n# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\n# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\"\"\"Page compiler plugin for pandoc.\n\nYou will need, of course, to install pandoc\n\"\"\"\n\n\nimport io\nimport os\nimport subprocess\n\nfrom nikola.plugin_categories import PageCompiler\nfrom nikola.utils import req_missing, makedirs, write_metadata\n\n\nclass CompilePandoc(PageCompiler):\n    \"\"\"Compile markups into HTML using pandoc.\"\"\"\n\n    name = \"pandoc\"\n    friendly_name = \"pandoc\"\n\n    def set_site(self, site):\n        \"\"\"Set Nikola site.\"\"\"\n        self.config_dependencies = [str(site.config['PANDOC_OPTIONS'])]\n        super().set_site(site)\n\n    def compile(self, source, dest, is_two_file=True, post=None, lang=None):\n        \"\"\"Compile the source file into HTML and save as dest.\"\"\"\n        makedirs(os.path.dirname(dest))\n        try:\n            subprocess.check_call(['pandoc', '-o', dest, source] + self.site.config['PANDOC_OPTIONS'])\n            with open(dest, 'r', encoding='utf-8-sig') as inf:\n                output, shortcode_deps = self.site.apply_shortcodes(inf.read())\n            with open(dest, 'w', encoding='utf-8') as outf:\n                outf.write(output)\n            if post is None:\n                if shortcode_deps:\n                    self.logger.error(\n                        \"Cannot save dependencies for post {0} (post unknown)\",\n                        source)\n            else:\n                post._depfile[dest] += shortcode_deps\n        except OSError as e:\n            if e.strreror == 'No such file or directory':\n                req_missing(['pandoc'], 'build this site (compile with pandoc)', python=False)\n\n    def compile_string(self, data, source_path=None, is_two_file=True, post=None, lang=None):\n        \"\"\"Compile into HTML strings.\"\"\"\n        raise ValueError(\"Pandoc compiler does not support compile_string due to multiple output formats\")\n\n    def create_post(self, path, **kw):\n        \"\"\"Create a new post.\"\"\"\n        content = kw.pop('content', None)\n        onefile = kw.pop('onefile', False)\n        # is_page is not used by create_post as of now.\n        kw.pop('is_page', False)\n        metadata = {}\n        metadata.update(self.default_metadata)\n        metadata.update(kw)\n        makedirs(os.path.dirname(path))\n        if not content.endswith('\\n'):\n            content += '\\n'\n        with io.open(path, \"w+\", encoding=\"utf8\") as fd:\n            if onefile:\n                fd.write(write_metadata(metadata, comment_wrap=True, site=self.site, compiler=self))\n            fd.write(content)\n", "path": "nikola/plugins/compile/pandoc.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Copyright \u00a9 2012-2021 Roberto Alsina and others.\n\n# Permission is hereby granted, free of charge, to any\n# person obtaining a copy of this software and associated\n# documentation files (the \"Software\"), to deal in the\n# Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish,\n# distribute, sublicense, and/or sell copies of the\n# Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice\n# shall be included in all copies or substantial portions of\n# the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY\n# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR\n# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\n# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\"\"\"Page compiler plugin for pandoc.\n\nYou will need, of course, to install pandoc\n\"\"\"\n\n\nimport io\nimport os\nimport subprocess\nfrom typing import List\nfrom pathlib import Path\n\nfrom nikola.plugin_categories import PageCompiler\nfrom nikola.utils import req_missing, makedirs, write_metadata\n\n\nclass CompilePandoc(PageCompiler):\n    \"\"\"Compile markups into HTML using pandoc.\"\"\"\n\n    name = \"pandoc\"\n    friendly_name = \"pandoc\"\n\n    def set_site(self, site):\n        \"\"\"Set Nikola site.\"\"\"\n        self.config_dependencies = [str(site.config['PANDOC_OPTIONS'])]\n        super().set_site(site)\n\n    def _get_pandoc_options(self, source: str) -> List[str]:\n        \"\"\"Obtain pandoc args from config depending on type and file extensions.\"\"\"\n        # Union[List[str], Dict[str, List[str]]]\n        config_options = self.site.config['PANDOC_OPTIONS']\n        type_ = type(config_options)\n        if type_ is list:\n            pandoc_options = config_options\n        elif type_ is dict:\n            ext = Path(source).suffix\n            try:\n                pandoc_options = config_options[ext]\n            except KeyError:\n                self.logger.warn('Setting PANDOC_OPTIONS to [], because extension {} is not defined in PANDOC_OPTIONS: {}.'.format(ext, config_options))\n                pandoc_options = []\n        else:\n            self.logger.warn('Setting PANDOC_OPTIONS to [], because PANDOC_OPTIONS is expected to be of type Union[List[str], Dict[str, List[str]]] but this is not: {}'.format(config_options))\n            pandoc_options = []\n        return pandoc_options\n\n    def compile(self, source, dest, is_two_file=True, post=None, lang=None):\n        \"\"\"Compile the source file into HTML and save as dest.\"\"\"\n        makedirs(os.path.dirname(dest))\n        try:\n            subprocess.check_call(['pandoc', '-o', dest, source] + self._get_pandoc_options(source))\n            with open(dest, 'r', encoding='utf-8-sig') as inf:\n                output, shortcode_deps = self.site.apply_shortcodes(inf.read())\n            with open(dest, 'w', encoding='utf-8') as outf:\n                outf.write(output)\n            if post is None:\n                if shortcode_deps:\n                    self.logger.error(\n                        \"Cannot save dependencies for post {0} (post unknown)\",\n                        source)\n            else:\n                post._depfile[dest] += shortcode_deps\n        except OSError as e:\n            if e.strreror == 'No such file or directory':\n                req_missing(['pandoc'], 'build this site (compile with pandoc)', python=False)\n\n    def compile_string(self, data, source_path=None, is_two_file=True, post=None, lang=None):\n        \"\"\"Compile into HTML strings.\"\"\"\n        raise ValueError(\"Pandoc compiler does not support compile_string due to multiple output formats\")\n\n    def create_post(self, path, **kw):\n        \"\"\"Create a new post.\"\"\"\n        content = kw.pop('content', None)\n        onefile = kw.pop('onefile', False)\n        # is_page is not used by create_post as of now.\n        kw.pop('is_page', False)\n        metadata = {}\n        metadata.update(self.default_metadata)\n        metadata.update(kw)\n        makedirs(os.path.dirname(path))\n        if not content.endswith('\\n'):\n            content += '\\n'\n        with io.open(path, \"w+\", encoding=\"utf8\") as fd:\n            if onefile:\n                fd.write(write_metadata(metadata, comment_wrap=True, site=self.site, compiler=self))\n            fd.write(content)\n", "path": "nikola/plugins/compile/pandoc.py"}]}