A general rule of thumb for Sublime is that if there’s a command that you can execute from a command prompt, you can automate it in Sublime. The only exception to this is that Sublime doesn’t directly support gathering input from something that you run (i.e. an interactive program), so for that you need a bit of extra setup.
What you want for something like this is a build system. Despite the name, this is something that you can provide exactly what you’d type on the command line and have Sublime execute it for you.
For your sample, that would look something like the following example:
{
"shell_cmd": "pandoc --filter pandoc-siteproc -t \"${file}\" -o \"${file_base_name}.docx\"",
"working_dir": "${file_path}",
"selector": "text.html.markdown"
}
The shell_cmd
specifies what you’d type (with various variables that expand out based on the current file name), working_dir
specifies what the “current” directory is set to while the program executes, and the selector
tells Sublime in what circumstances it should automatically select this build.
To use it, select Tools > Build System > New Build System
from the menu, replace the stub text with this, and then save it as a sublime-build
file in the location that Sublime will default to (which is your User
package).
You can then select it directly from Tools > Build System
in the menu (it will appear with the same name as you used when you saved the file), or select Automatic
from that menu and Sublime will pick this build when the current file is a markdown file.
Important Tip: external programs expect the file to be on disk so they can access them, so make sure that if you create a new file, you save it manually at least once to give it a name. The Tools > Save All On Build
item will make sure unsaved files are automatically saved before a build starts, but this only applies to files that have a name on disk already.
The links above are to the documentation on build systems. If you need more guidance/examples, I have a video series on build systems that covers the topic in details.