Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow to enable/disable extensions individually on commandline and in defaults files? #11593

@bpj

Description

@bpj

What about allowing to specify extensions individually by a --reader-ext +foo --writer-ext -bar or -R +foo -W -bar and in defaults files a mapping

reader-extensions:
  foo: true
writer-extensions:
  bar: false

just like for pandoc.read and pandoc.write in the Lua API, allowing extensions to be overridden individually between different defaults files, and overriding defaults file settings individually on the command line?

For example in my usual defaults file for markdown-to-markdown (cleanup) conversion I have almost the same extensions for input and output except that the smart extension has opposite values — because I use a filter which converts Quoted elements to hardcoded Unicode quotes based on the document language and/or attributes on divs —, plus that I sometimes want to disable smart on input so as to inhibit that conversion. As is I have to

  1. Have two almost identical strings as values of from: and to: in the defaults file.
  2. Type a string on the command line repeating all the extensions changing the value only for the one(s) I want to override.

With this change, provided YAML Mergekeys are enabled (are they?), I could instead have this in the defaults file:

from: markdown
to: markdown
reader-extensions: &extensions
  four_space_rule: true
  shortcut_reference_links: false
  tex_math_dollars: false
  smart: true
writer-extensions:
  <<: *extensions
  smart: false
filters:
  - quotes.lua
  # more

and to change only smart on the commandline in Vim

:%!pandoc -d md2md -R -smart 

also I could then presumably just say

$ pandoc -d md2md -L dl2ul.lua -w gfm -o README.md docu.md

to convert to GFM with the same set of extensions as for Pandoc markdown output, while as-is I have to have a separate md2gfm.yaml with

defaults: md2md.yaml
to: 'gfm+four_space_rule-shortcut_reference_links-tex_math_dollars-smart'
filters:
  - dl2ul.lua

which isn’t ideal from a maintenance POV.

TBH I have a feature in that quotes filter whereby I can “disable” it on the command line with -Mquotes-style=dumb so this particular example can be worked around, but what if the crucial extension were tex_math_dollars?

FWIW I've tried to write a "YAML preprocessor" which would take a list of files with a structure like the above and generate from: and to: values accordingly. In fact that is just one of the features — along with path expansion, disabling filters and "smart" merging of mappings in metadata and variables — of my update-pdc-dfts.pl script but to maintain that script and through it a defaults-defs and a defaults directory is a burden I'd like to get away from. Having a script which takes YAML config files to merge and generate YAML config files can get confusing! If some of that could be done in a simpler way by Pandoc itself everyone would benefit.

PS: I searched for issues with "extensions enable disable" but found nothing relevant-looking.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions