diff options
| author | 2021-04-22 20:23:51 -0400 | |
|---|---|---|
| committer | 2021-04-22 20:23:51 -0400 | |
| commit | 5fe4d85d8450575556385f20c46d67887009e245 (patch) | |
| tree | e07d531240670225499657eff04a16105eb4bb5f /nikola/plugins/compile/pandoc.py | |
| parent | 501ee1930f5424ac00be29a7537a74e30c5d901f (diff) | |
| parent | 8eeed31eb2f86ac982fa4b26f93b15828289c56d (diff) | |
Update upstream source from tag 'upstream/8.1.3'
Update to upstream version '8.1.3'
with Debian dir ff84f28157b98ab52cbb563f4853d749beb4be60
Diffstat (limited to 'nikola/plugins/compile/pandoc.py')
| -rw-r--r-- | nikola/plugins/compile/pandoc.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/nikola/plugins/compile/pandoc.py b/nikola/plugins/compile/pandoc.py index af14344..62d3e88 100644 --- a/nikola/plugins/compile/pandoc.py +++ b/nikola/plugins/compile/pandoc.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2020 Roberto Alsina and others. +# Copyright © 2012-2021 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -33,6 +33,8 @@ You will need, of course, to install pandoc 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,29 @@ class CompilePandoc(PageCompiler): 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'] + if isinstance(config_options, (list, tuple)): + pandoc_options = list(config_options) + elif isinstance(config_options, dict): + ext = Path(source).suffix + try: + pandoc_options = list(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: |
