tbfisher / sublimetext-Pandoc

A Sublime Text plugin that uses Pandoc to convert text from one markup format into another. Pandoc can convert documents in markdown, reStructuredText, textile, HTML, DocBook, LaTeX, MediaWiki markup, OPML, or Haddock markup to XHTML, HTML5, HTML slide shows using Slidy, reveal.js, Slideous, S5, or DZSlides, Microsoft Word docx, OpenOffice/LibreOffice ODT, OpenDocument XML, EPUB version 2 or 3, FictionBook2, DocBook, GNU TexInfo, Groff man pages, Haddock markup, OPML, LaTeX, ConTeXt, LaTeX Beamer slides, PDF via LaTeX, Markdown, reStructuredText, AsciiDoc, MediaWiki markup, Emacs Org-Mode, Textile, or custom writers can be written in lua.
MIT License
137 stars 26 forks source link

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

Closed dahanbn closed 4 years ago

dahanbn commented 7 years ago

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?

dahanbn commented 7 years ago

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.

dahanbn commented 7 years ago

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: https://github.com/wbond/package_control/issues/1255

hadrienj commented 6 years ago

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

hadrienj commented 6 years ago

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",
         ],
      },
MPvHarmelen commented 4 years ago

Fixed in #64