Sublime Forum

How to define default variant for a custom build system

#1

Hi,

I would like to have a build command where I can run different commands on a markdown file to convert it to html, docx or a pdf.

Here is a short example. Each variant runs correctly, but there is no default variant if I run it without variants?

{
“selector”: “text.html.markdown”,
“working_dir”: “$file_path”,
“variants”:
[
{
“name”: “pandoc => pdf (scrlttr2dh)”,
“cmd”: [“pandoc.exe”, “$file”, “–from”, “markdown”, “–template”, “scrlttr2dh.latex”, “–pdf-engine=lualatex”, “–to”, “pdf”, “-o”, “${file/\.md/\.pdf/}” ],
},
{
“name”: “pandoc => html”,
“cmd”: [“pandoc.exe”, “$file”, “–from”, “markdown”, “–to”, “html”, “-o”, “${file/\.md/\.html/}” ]
}
]
}

Bonus question:

Is there a way to open the created pdf with default pdf reader after creating it within the build system?

0 Likes

#2

Add a cmd key to the base build (i.e. not in the variants key, and that will be what the build does unless you pick one of the variants.

You can also run multiple commands via shell_cmd, such as:

"shell_cmd": "this && that",

Which runs the command this, and then if it suceeds, also runs the command that.

You could probably add extra items to the cmd arrays and add "shell": true to the build to get the same effect.

1 Like

#3

Thanks, Odat.

Is it possible to create the command “cmd” as an string as well?

e.g. “cmd”: “pandoc.exe $file”,

I tried it but then a filename with spaces isn’t resolved correctly.

0 Likes

#4

Odat,

figured it out myself. :slight_smile:

"shell": true,
"shell_cmd": "pandoc.exe \"$file\" --from markdown --template scrlttr2dh.latex --pdf-engine=lualatex --to pdf -o \"$file_base_name.pdf\"",

And here the variant with automatically opening the pdf afterwards:

"shell_cmd": "pandoc.exe \"$file\" --from markdown --template scrlttr2dh.latex --pdf-engine=lualatex --to pdf -o \"$file_base_name.pdf\" && \"$file_base_name.pdf\"",
0 Likes