|
1 | 1 | <script setup> |
2 | | -import PlatformCodePreview from "./PlatformCodePreview.vue"; |
3 | 2 | import CodePreview from "./CodePreview.vue"; |
| 3 | +import { createHighlighter } from 'shiki'; |
| 4 | +import { onMounted, ref } from "vue"; |
| 5 | +import axios from "axios"; |
| 6 | +
|
| 7 | +const grammarUrl = "https://raw.githubusercontent.com/stjude-rust-labs/sprocket-vscode/refs/heads/main/syntaxes/wdl.tmGrammar.json"; |
| 8 | +const installCode = ref(null); |
| 9 | +const wdlCode = ref(null); |
| 10 | +const runCode = ref(null); |
| 11 | +
|
| 12 | +onMounted(async () => { |
| 13 | + const wdl = await axios.get(grammarUrl); |
| 14 | +
|
| 15 | + const highlighter= await createHighlighter({ |
| 16 | + themes: ["github-dark"], |
| 17 | + langs: ["bash", wdl.data] |
| 18 | + }); |
| 19 | +
|
| 20 | + installCode.value = await highlighter.codeToHtml("cargo install sprocket --locked", { |
| 21 | + lang: "bash", |
| 22 | + theme: "github-dark", |
| 23 | + colorReplacements: { |
| 24 | + "#24292e": "none" |
| 25 | + } |
| 26 | + }); |
| 27 | +
|
| 28 | + const wdlCodeText = `version 1.2 |
| 29 | +
|
| 30 | +workflow count_lines { |
| 31 | + input { File input_file } |
| 32 | + call Count { input: file = input_file } |
| 33 | + output { Int num_lines = Count.num_lines } |
| 34 | +} |
| 35 | +
|
| 36 | +task Count { |
| 37 | + input { File file } |
| 38 | + command { wc -l \${file} | awk '{print $1}' } |
| 39 | + output { Int num_lines = read_int(stdout()) } |
| 40 | +}`; |
| 41 | +
|
| 42 | + wdlCode.value = await highlighter.codeToHtml(wdlCodeText, { |
| 43 | + lang: "wdl", |
| 44 | + theme: "github-dark", |
| 45 | + colorReplacements: { |
| 46 | + "#24292e": "none" |
| 47 | + } |
| 48 | + }); |
| 49 | +
|
| 50 | + runCode.value = await highlighter.codeToHtml("sprocket run example.wdl", { |
| 51 | + lang: "bash", |
| 52 | + theme: "github-dark", |
| 53 | + colorReplacements: { |
| 54 | + "#24292e": "none" |
| 55 | + } |
| 56 | + }); |
| 57 | +
|
| 58 | +}); |
| 59 | +
|
4 | 60 | </script> |
5 | 61 |
|
6 | 62 | <template> |
@@ -31,25 +87,25 @@ import CodePreview from "./CodePreview.vue"; |
31 | 87 | <!-- Right: Code Cards --> |
32 | 88 | <section class="hero__right-column"> |
33 | 89 | <!-- Card 1: Install --> |
34 | | - <PlatformCodePreview |
35 | | - windows-command="cargo install sprocket" |
36 | | - mac-command="cargo install sprocket" |
37 | | - unix-command="cargo install sprocket" |
38 | | - /> |
| 90 | + <div class="card" v-if="installCode != null"> |
| 91 | + <CodePreview header="bash" preformatted> |
| 92 | + <div v-html="installCode"></div> |
| 93 | + </CodePreview> |
| 94 | + </div> |
39 | 95 |
|
40 | 96 | <!-- Card 2: WDL Example --> |
41 | | - <div class="card"> |
42 | | - <CodePreview header="WDL" preformatted> |
43 | | - <slot /> |
| 97 | + <div class="card" v-if="wdlCode != null"> |
| 98 | + <CodePreview header="wdl" preformatted> |
| 99 | + <div v-html="wdlCode"></div> |
44 | 100 | </CodePreview> |
45 | 101 | </div> |
46 | 102 |
|
47 | 103 | <!-- Card 3: Run Example --> |
48 | | - <PlatformCodePreview |
49 | | - windows-command="sprocket run example.wdl -vvv" |
50 | | - mac-command="sprocket run example.wdl -vvv" |
51 | | - unix-command="sprocket run example.wdl -vvv" |
52 | | - /> |
| 104 | + <div class="card" v-if="runCode != null"> |
| 105 | + <CodePreview header="bash" preformatted> |
| 106 | + <div v-html="runCode"></div> |
| 107 | + </CodePreview> |
| 108 | + </div> |
53 | 109 | </section> |
54 | 110 | </div> |
55 | 111 | </div> |
|
0 commit comments