tbfisher/sublimetext-Pandoc

How to specify a outputfile based on the basefilename of the input file

Closed this issue · 5 comments

Hi,

I am new to ST3 and your Pandoc package and as a non programmer I struggle to find the right option. I would like that the output file for pandoc should be based on the input filename.

Example:
input: document1.md
output: document1.docx

I tried to add the following in my pandoc user settings:

"pandoc-arguments": [
          "-t", "docx",
          "-o", "$file_base_name.docx",
          // if -o or --output missing, will write to a temporary file
          // "--output=~/Downloads/output.pdf"
        ]

But that generates unfortunately only a file called $file_base_name.docx.

How would I do that?

I think I found a solution:

Code:
replacing the line output_path = tempfile.NamedTemporaryFile().name

with

           input_file = self.view.file_name()
            if input_file:
                output_path = os.path.splitext(os.path.basename(input_file))[0] # use basename of view
            else: 
                output_path = tempfile.NamedTemporaryFile().name # use a temporary file name

That will automatically create an outputfile with the basename of the view and corresponding extensions of the files mentioned in pandoc-format-file. If the view has no filename than it will generate a temporary file.

Just noticed that you already have a different solution in your master to achieve that. Unfortunately, the option output-local isn't available in the pandoc package that is installed via PackageControl. The info there says your latest version is 12 month old.

I opened an issue there to fix that. Hope that's the right way.

Here is the link to the issue: wbond/package_control#1255

Hi @dahanbn, thank you for opening this issue I have the exact same problem!

I installed the package manually but how do you specify the option output-local?

Thanks

I just found how to do it: add 'out-local' in the wanted transformation. Here is an example:

    "PDF TOC": {
        "scope": {
          "text.html": "html",
          "text.html.markdown": "markdown",
          },
        "out-local": true,
        "pandoc-arguments": [
          "-s", "--toc", "--number-sections", "--parse-raw",
          "-t", "pdf",
         ],
      },

Fixed in #64