Enter-tainer / typst-preview

[DEPRECATED] Use tinymist instead
https://Enter-tainer.github.io/typst-preview/
MIT License
452 stars 21 forks source link

Convert launching preview commands to a single unified command #224

Open Myriad-Dreamin opened 5 months ago

Myriad-Dreamin commented 5 months ago

Background: In my project, I can provide sys.inputs.at("target") to control the target of a document. When a target is set to "webpage", it is compiled and suitable for viewing in website. When a target is set to "ebook", it is compiled as a e-book PDF and suitable for viewing in online or offline pdf viewer.

To edit styles for document targeting to "webpage", I want to launch preview with sys.inputs arguments.


Currently there are four commands to launch preview.

As feature increased (e.g. sys.inputs), the matrix becomes larger and unmaintainable. So I want to convert the "open/launch" action into a single command. And create four corresponding auto-detected tasks to replace these commands. The final effect should look like this:

image

We will have these auto detected tasks (also as a start-up task template):

And we can invoke a typst-preview.launch command in task:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "preview",
      "command": "${command:typst-preview.launch}",
      "args": {
        "openIn": "webview", // v.s. in browser
        "mode": "document", // v.s. slide mode
        "inputs": {
          "target": "webpage",
          "theme-setting": "themes/ayu.toml"
        }
      }
    }
  ]
}

All of arguments in typst-preview.launch are optional so we can also have a default command to launch without configuration or interactively.

And we can disable auto detected tasks as user preferences.

https://github.com/microsoft/vscode/blob/c7ea84b4f5e779a98e93bd1f48502d83403f16c3/extensions/gulp/src/main.ts#L140-L150

Enter-tainer commented 5 months ago

I think it is ok to have to add custom sys.inputs. For existing ones, I prefer keeping them instead of replacing them with tasks