Skip to content

Commit 60d8ba8

Browse files
mcanouilvezwork
andauthored
feat: improve Quarto snippets (#946)
* feat: improve Quarto snippets Fix a missing comma in the horizontal rule prefix array that rendered the file invalid JSON. Fix the raw codeblock syntax so Pandoc raw attributes use the required `=` prefix (for example `{=html}` rather than `{html}`). Fix `htm` to `html` in the fenced code block language dropdown, drop the non-standard `console`, normalise `c++`/`c#` to `cpp`/`csharp`, and add commonly used languages (bash, html, r, rust, sql, toml, typescript, xml, yaml). Add `typst` to the raw code block dropdown. Restore the `.column` content lines and add tab stops to `columns2` and `columns3` so users can fill each column, drop the trailing `<!-- end columns -->` marker that leaked an HTML comment into the rendered output, and append a final `$0` so the cursor exits the block cleanly. Normalise final cursor placement with `$0` on single-line snippets (quote, strikethrough, headings 1-6). Surround block-level snippets (headings, lists, code blocks, divs, blockquote, horizontal rule) with empty lines so the inserted content does not collide with adjacent paragraphs and, for the horizontal rule, cannot be parsed as a setext heading. Add five new snippets: `yaml` for frontmatter, `figure` for an image with `#fig-` id and `fig-alt`, `xref` for a Quarto cross-reference div (fig/tbl/lst), `list-table` for a Quarto `.list-table` div, and `tabset` for a `.panel-tabset` block. * docs: add changelog entry for snippets improvements --------- Co-authored-by: Elliot <key.draw@gmail.com>
1 parent 20e529f commit 60d8ba8

2 files changed

Lines changed: 149 additions & 30 deletions

File tree

apps/vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Added support for Positron's statement execution feature that reports the approximate line number of the parse error (<https://github.com/quarto-dev/quarto/pull/919>).
66
- Fixed a bug where `Quarto: Format Cell` would notify you that no formatter was available for code cells that were already formatted (<https://github.com/quarto-dev/quarto/pull/933>).
77
- No longer claim `.typ` files. Typst syntax highlighting in Quarto documents is unaffected, but standalone Typst files are now left to dedicated extensions like Tinymist (<https://github.com/quarto-dev/quarto/pull/943>).
8+
- Improved Quarto snippets: fixed invalid JSON, corrected the raw code block syntax, refreshed and alphabetised the fenced code block language list, added `typst` to raw code blocks, restored content and tab stops in the `columns2`/`columns3` snippets, ensured block-level snippets are surrounded by empty lines, and added `yaml`, `figure`, `xref`, `list-table`, and `tabset` snippets (<https://github.com/quarto-dev/quarto/pull/946>).
89
- Preserve Quarto code cell option directives (e.g. `#| label: foo`) when formatting embedded code. The directives are now stripped from the virtual document before being handed to the language formatter, so formatters such as Black, autopep8, and styler can no longer reflow or rewrite them (<https://github.com/quarto-dev/quarto/pull/655>).
910
- Fixed a bug where closing the Quarto Preview terminal via the trash icon did not clean up intermediate `.quarto_ipynb` files (<https://github.com/quarto-dev/quarto/pull/947>).
1011

apps/vscode/snippets/quarto.code-snippets

Lines changed: 148 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"Insert quoted text": {
1313
"prefix": "quote",
14-
"body": "> ${1:${TM_SELECTED_TEXT}}",
14+
"body": ["", "> ${1:${TM_SELECTED_TEXT}}", "", "$0"],
1515
"description": "Insert quoted text"
1616
},
1717
"Insert inline code": {
@@ -27,73 +27,86 @@
2727
"Insert fenced code block": {
2828
"prefix": "fenced codeblock",
2929
"body": [
30-
"```${1|python,c,c++,c#,ruby,go,java,php,htm,css,javascript,json,markdown,console|}",
30+
"",
31+
"```${1|bash,c,cpp,csharp,css,go,html,java,javascript,json,markdown,php,python,r,ruby,rust,sql,toml,typescript,xml,yaml|}",
3132
"${TM_SELECTED_TEXT}$0",
32-
"```"
33+
"```",
34+
""
3335
],
3436
"description": "Insert fenced code block"
3537
},
3638
"Insert executable code block": {
3739
"prefix": "executable codeblock",
3840
"body": [
41+
"",
3942
"```{${1|python,r,julia,ojs,sql,bash,mermaid,dot|}}",
4043
"${TM_SELECTED_TEXT}$0",
41-
"```"
44+
"```",
45+
""
4246
],
4347
"description": "Insert executable code block"
4448
},
4549
"Insert raw code block": {
4650
"prefix": "raw codeblock",
4751
"body": [
48-
"```{${1|html,latex,openxml,opendocument,asciidoc,docbook,markdown,dokuwiki,fb2,gfm,haddock,icml,ipynb,jats,jira,json,man,mediawiki,ms,muse,opml,org,plain,rst,rtf,tei,texinfo,textile,xwiki,zimwiki,native|}}",
52+
"",
53+
"```{=${1|html,latex,typst,openxml,opendocument,asciidoc,docbook,markdown,dokuwiki,fb2,gfm,haddock,icml,ipynb,jats,jira,json,man,mediawiki,ms,muse,opml,org,plain,rst,rtf,tei,texinfo,textile,xwiki,zimwiki,native|}}",
4954
"${TM_SELECTED_TEXT}$0",
50-
"```"
55+
"```",
56+
""
5157
],
5258
"description": "Insert raw code block"
5359
},
5460
"Insert heading level 1": {
5561
"prefix": "heading1",
56-
"body": "# ${1:${TM_SELECTED_TEXT}}",
62+
"body": ["", "# ${1:${TM_SELECTED_TEXT}}", "", "$0"],
5763
"description": "Insert heading level 1"
5864
},
5965
"Insert heading level 2": {
6066
"prefix": "heading2",
61-
"body": "## ${1:${TM_SELECTED_TEXT}}",
67+
"body": ["", "## ${1:${TM_SELECTED_TEXT}}", "", "$0"],
6268
"description": "Insert heading level 2"
6369
},
6470
"Insert heading level 3": {
6571
"prefix": "heading3",
66-
"body": "### ${1:${TM_SELECTED_TEXT}}",
72+
"body": ["", "### ${1:${TM_SELECTED_TEXT}}", "", "$0"],
6773
"description": "Insert heading level 3"
6874
},
6975
"Insert heading level 4": {
7076
"prefix": "heading4",
71-
"body": "#### ${1:${TM_SELECTED_TEXT}}",
77+
"body": ["", "#### ${1:${TM_SELECTED_TEXT}}", "", "$0"],
7278
"description": "Insert heading level 4"
7379
},
7480
"Insert heading level 5": {
7581
"prefix": "heading5",
76-
"body": "##### ${1:${TM_SELECTED_TEXT}}",
82+
"body": ["", "##### ${1:${TM_SELECTED_TEXT}}", "", "$0"],
7783
"description": "Insert heading level 5"
7884
},
7985
"Insert heading level 6": {
8086
"prefix": "heading6",
81-
"body": "###### ${1:${TM_SELECTED_TEXT}}",
87+
"body": ["", "###### ${1:${TM_SELECTED_TEXT}}", "", "$0"],
8288
"description": "Insert heading level 6"
8389
},
8490
"Insert unordered list": {
8591
"prefix": "unordered list",
86-
"body": ["- ${1:first}", "- ${2:second}", "- ${3:third}", "$0"],
92+
"body": ["", "- ${1:first}.", "- ${2:second}.", "- ${3:third}.", "", "$0"],
8793
"description": "Insert unordered list"
8894
},
8995
"Insert ordered list": {
9096
"prefix": "ordered list",
91-
"body": ["1. ${1:first}", "2. ${2:second}", "3. ${3:third}", "$0"],
97+
"body": [
98+
"",
99+
"1. ${1:first}.",
100+
"2. ${2:second}.",
101+
"3. ${3:third}.",
102+
"",
103+
"$0"
104+
],
92105
"description": "Insert ordered list"
93106
},
94107
"Insert horizontal rule": {
95-
"prefix": ["horizontal rule", "horizontal line"]
96-
"body": "----------\n",
108+
"prefix": ["horizontal rule", "horizontal line"],
109+
"body": ["", "---", "", "$0"],
97110
"description": "Insert horizontal line"
98111
},
99112
"Insert link": {
@@ -108,17 +121,25 @@
108121
},
109122
"Insert strikethrough": {
110123
"prefix": "strikethrough",
111-
"body": "~~${1:${TM_SELECTED_TEXT}}~~",
124+
"body": "~~${1:${TM_SELECTED_TEXT}}~~$0",
112125
"description": "Insert strikethrough"
113126
},
114127
"Insert div block": {
115128
"prefix": "div",
116-
"body": ["::: {.${1:class}}", "${TM_SELECTED_TEXT}$0", ":::"],
129+
"body": [
130+
"",
131+
"::: {${1:#id .class1 key=value}}",
132+
"",
133+
"${TM_SELECTED_TEXT}$0",
134+
"",
135+
":::",
136+
""
137+
],
117138
"description": "Insert div block"
118139
},
119140
"Insert fragment block": {
120141
"prefix": "fragment",
121-
"body": ["::: {.fragment}", "${TM_SELECTED_TEXT}$0", ":::"],
142+
"body": ["", "::: {.fragment}", "", "${TM_SELECTED_TEXT}$0", "", ":::", ""],
122143
"description": "Insert fragment block"
123144
},
124145
"Insert span": {
@@ -129,46 +150,143 @@
129150
"Insert callout block": {
130151
"prefix": "callout",
131152
"body": [
153+
"",
132154
"::: {.${1|callout,callout-note,callout-tip,callout-important,callout-caution,callout-warning|}}",
155+
"",
133156
"${TM_SELECTED_TEXT}$0",
134-
":::"
157+
"",
158+
":::",
159+
""
135160
],
136161
"description": "Insert callout block"
137162
},
138163
"Insert two columns": {
139164
"prefix": "columns2",
140165
"body": [
166+
"",
141167
"::: {.columns}",
142-
168+
"",
143169
"::: {.column}",
170+
"",
171+
"$1",
172+
"",
144173
":::",
145-
174+
"",
146175
"::: {.column}",
176+
"",
177+
"$2",
178+
"",
147179
":::",
148-
180+
"",
149181
":::",
150-
"<!-- end columns -->"
151-
182+
"",
183+
"$0"
152184
],
153185
"description": "Insert two columns"
154186
},
155187
"Insert three columns": {
156188
"prefix": "columns3",
157189
"body": [
190+
"",
158191
"::: {.columns}",
159-
192+
"",
160193
"::: {.column}",
194+
"",
195+
"$1",
196+
"",
161197
":::",
162-
198+
"",
163199
"::: {.column}",
200+
"",
201+
"$2",
202+
"",
164203
":::",
165-
204+
"",
166205
"::: {.column}",
206+
"",
207+
"$3",
208+
"",
167209
":::",
168-
210+
"",
169211
":::",
170-
"<!-- end columns -->"
212+
"",
213+
"$0"
171214
],
172215
"description": "Insert three columns"
216+
},
217+
"Insert YAML frontmatter": {
218+
"prefix": "yaml",
219+
"body": [
220+
"---",
221+
"title: ${1:title}",
222+
"author: ${2:author}",
223+
"format: ${3|html,pdf,docx,typst,revealjs|}",
224+
"---",
225+
"",
226+
"$0"
227+
],
228+
"description": "Insert YAML frontmatter"
229+
},
230+
"Insert figure": {
231+
"prefix": "figure",
232+
"body": "![${1:caption}](${2:path}){#fig-${3:id} fig-alt=\"${4:alt}\"}$0",
233+
"description": "Insert figure with caption and alt text"
234+
},
235+
"Insert cross-reference div": {
236+
"prefix": "xref",
237+
"body": [
238+
"",
239+
"::: {#${1|fig-,tbl-,lst-|}${2:id}}",
240+
"",
241+
"${3:content}",
242+
"",
243+
"${4:caption}",
244+
"",
245+
":::",
246+
"",
247+
"$0"
248+
],
249+
"description": "Insert cross-reference div (figure, table, or listing)"
250+
},
251+
"Insert list table": {
252+
"prefix": "list-table",
253+
"body": [
254+
"",
255+
"::: {.list-table}",
256+
"",
257+
"- - ${1:header 1}",
258+
" - ${2:header 2}",
259+
"",
260+
"- - ${3:row 1 col 1}",
261+
" - ${4:row 1 col 2}",
262+
"",
263+
"- - ${5:row 2 col 1}",
264+
" - ${6:row 2 col 2}",
265+
"",
266+
":::",
267+
"",
268+
"$0"
269+
],
270+
"description": "Insert list table"
271+
},
272+
"Insert tabset panel": {
273+
"prefix": "tabset",
274+
"body": [
275+
"",
276+
"::: {.panel-tabset}",
277+
"",
278+
"## ${1:Tab 1}",
279+
"",
280+
"${2:content}",
281+
"",
282+
"## ${3:Tab 2}",
283+
"",
284+
"${4:content}",
285+
"",
286+
":::",
287+
"",
288+
"$0"
289+
],
290+
"description": "Insert tabset panel"
173291
}
174292
}

0 commit comments

Comments
 (0)