Skip to content

Commit d1d7e94

Browse files
authored
Replace pre-release feature includes with version-aware shortcode (#1961)
* Consolidate prerelease extension with new prerelease-callout shortcode Rename _extensions/prerelease-docs-url/ to _extensions/prerelease/ and combine both shortcodes into a single Lua file with shared helpers: - prerelease-docs-url: existing shortcode for prerelease subdomain links - prerelease-callout: new shortcode that shows version-aware callouts for feature docs (hidden after release) and blog posts (switches from pre-release to released text) * Replace _pre-release-feature includes with prerelease-callout shortcode Migrate 5 include references across 3 files (all version 1.5, already released) to use the new version-aware shortcode instead. * Replace blog post feature includes with prerelease-callout shortcode Migrate 5 blog posts to use {{< prerelease-callout X.Y type="blog" >}} instead of including shared _quarto-X.Y-feature.qmd files. * Remove old pre-release feature include files These files are no longer needed now that the prerelease-callout shortcode generates callout content dynamically based on version. * Add README for prerelease extension Documents both shortcodes (prerelease-docs-url and prerelease-callout), usage examples, and version comparison logic with scenario table. * Replace remaining 1.9 _pre-release-feature includes with shortcode Migrate 8 additional include references (only present on prerelease branch) to use the version-aware prerelease-callout shortcode. * Replace missed _pre-release-feature include in syntax highlighting doc
1 parent c23df29 commit d1d7e94

30 files changed

Lines changed: 225 additions & 118 deletions

File tree

_extensions/prerelease-docs-url/prerelease-docs-url.lua

Lines changed: 0 additions & 62 deletions
This file was deleted.

_extensions/prerelease/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Prerelease Extension
2+
3+
Version-aware shortcodes for prerelease content on quarto-web. Both shortcodes use the `version` key from `_quarto.yml` (or `_quarto-prerelease-docs.yml` on the prerelease profile) to determine whether a feature version has been released.
4+
5+
## Shortcodes
6+
7+
### `prerelease-docs-url`
8+
9+
Returns `"prerelease."` when the referenced version's docs live on prerelease.quarto.org, or `""` when they're on quarto.org. Use in link URLs:
10+
11+
```markdown
12+
[documentation](https://{{< prerelease-docs-url 1.9 >}}quarto.org/docs/feature.html)
13+
```
14+
15+
### `prerelease-callout`
16+
17+
Shows a version-aware callout note. Two modes:
18+
19+
**Feature docs** (default) — callout disappears after release:
20+
21+
```markdown
22+
{{< prerelease-callout 1.9 >}}
23+
```
24+
25+
- Unreleased: shows "Pre-release Feature" callout with link to prerelease download
26+
- Released: shows nothing
27+
28+
**Blog posts** (`type="blog"`) — callout text changes after release:
29+
30+
```markdown
31+
{{< prerelease-callout 1.9 type="blog" >}}
32+
```
33+
34+
- Unreleased: shows "Pre-release Feature" callout with link to prerelease download
35+
- Released: shows "Quarto X.Y Feature" callout with link to stable download page
36+
37+
## Version comparison logic
38+
39+
On the **main site** (`version` = current stable release): a feature is unreleased when `ref_version > site_version`.
40+
41+
On the **prerelease site** (profile `prerelease-docs`, `version` = current prerelease cycle): a feature is unreleased when `ref_version >= site_version`.
42+
43+
The `>=` vs `>` difference handles the fact that the prerelease site's version equals the in-progress release, while main's version equals the last stable release.
44+
45+
### Example scenarios (feature docs)
46+
47+
| Phase | Site | `version` | ref | Unreleased? | Output |
48+
|---|---|---|---|---|---|
49+
| 1.9 in dev | main | 1.8 | 1.9 | 1.9 > 1.8 ✓ | Pre-release callout |
50+
| 1.9 in dev | prerelease | 1.9 | 1.9 | 1.9 >= 1.9 ✓ | Pre-release callout |
51+
| 1.9 released | main | 1.9 | 1.9 | 1.9 > 1.9 ✗ | Nothing |
52+
| 1.9 released | prerelease | 2.0 | 1.9 | 1.9 >= 2.0 ✗ | Nothing |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
title: Prerelease Docs URL
1+
title: Prerelease
22
author: Quarto
33
version: 0.0.1
44
contributes:
55
shortcodes:
6-
- prerelease-docs-url.lua
6+
- prerelease.lua
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
-- Version-aware shortcodes for prerelease content.
2+
--
3+
-- prerelease-docs-url:
4+
-- {{< prerelease-docs-url 1.9 >}}
5+
-- Returns "prerelease." when the referenced version's docs live on
6+
-- prerelease.quarto.org, or "" when they're on quarto.org.
7+
--
8+
-- prerelease-callout:
9+
-- {{< prerelease-callout 1.9 >}}
10+
-- Shows a "Pre-release Feature" callout when the referenced version is
11+
-- unreleased. Shows nothing once the version is released.
12+
--
13+
-- {{< prerelease-callout 1.9 type="blog" >}}
14+
-- Blog mode: shows "Pre-release Feature" callout when unreleased,
15+
-- switches to "Quarto X.Y Feature" callout once released.
16+
--
17+
-- Both shortcodes use the `version` key from _quarto.yml metadata and
18+
-- the `prerelease-docs` profile to determine whether a version is released.
19+
20+
--- Strip surrounding quotes from a shortcode argument.
21+
local function strip_quotes(s)
22+
return s:gsub('^"(.*)"$', '%1'):gsub("^'(.*)'$", '%1')
23+
end
24+
25+
--- Parse the version argument and site version metadata.
26+
-- Returns ref_version, branch_version (as pandoc.types.Version), or
27+
-- nil plus an error Blocks/Inlines on failure.
28+
local function parse_versions(shortcode_name, args, meta, context)
29+
local ref_str = quarto.shortcode.read_arg(args, 1)
30+
if ref_str == nil then
31+
return nil, nil, quarto.shortcode.error_output(
32+
shortcode_name,
33+
"requires a version argument, e.g. {{< " .. shortcode_name .. " 1.9 >}}",
34+
context
35+
)
36+
end
37+
ref_str = strip_quotes(ref_str)
38+
39+
local version_str = meta["version"] and pandoc.utils.stringify(meta["version"]) or nil
40+
if not version_str or version_str == "" then
41+
return nil, nil, quarto.shortcode.error_output(
42+
shortcode_name,
43+
"missing 'version' in document metadata",
44+
context
45+
)
46+
end
47+
48+
local ok_branch, branch_version = pcall(pandoc.types.Version, version_str)
49+
if not ok_branch then
50+
return nil, nil, quarto.shortcode.error_output(
51+
shortcode_name,
52+
"invalid metadata version '" .. version_str .. "'",
53+
context
54+
)
55+
end
56+
57+
local ok_ref, ref_version = pcall(pandoc.types.Version, ref_str)
58+
if not ok_ref then
59+
return nil, nil, quarto.shortcode.error_output(
60+
shortcode_name,
61+
"invalid version argument '" .. ref_str .. "'",
62+
context
63+
)
64+
end
65+
66+
return ref_version, branch_version, nil
67+
end
68+
69+
--- Check whether a referenced version is unreleased.
70+
-- On prerelease site (profile prerelease-docs): ref >= site version
71+
-- On main site: ref > site version
72+
local function is_unreleased(ref_version, branch_version)
73+
if quarto.project.profile:includes("prerelease-docs") then
74+
return ref_version >= branch_version
75+
else
76+
return ref_version > branch_version
77+
end
78+
end
79+
80+
--- Parse a markdown string into pandoc Blocks.
81+
local function md_to_blocks(md)
82+
return pandoc.read(md, "markdown").blocks
83+
end
84+
85+
-- Shortcode: prerelease-docs-url
86+
local function docs_url_handler(args, kwargs, meta, raw_args, context)
87+
local ref_version, branch_version, err = parse_versions(
88+
"prerelease-docs-url", args, meta, context
89+
)
90+
if err then return err end
91+
92+
-- On the prerelease site, always link to prerelease
93+
if quarto.project.profile:includes("prerelease-docs") then
94+
return pandoc.Str("prerelease.")
95+
end
96+
97+
if ref_version <= branch_version then
98+
return pandoc.Str("")
99+
else
100+
return pandoc.Str("prerelease.")
101+
end
102+
end
103+
104+
-- Shortcode: prerelease-callout
105+
local function callout_handler(args, kwargs, meta, raw_args, context)
106+
local ref_version, branch_version, err = parse_versions(
107+
"prerelease-callout", args, meta, context
108+
)
109+
if err then return err end
110+
111+
local ref_str = strip_quotes(quarto.shortcode.read_arg(args, 1))
112+
local callout_type = kwargs["type"] or ""
113+
local is_blog = callout_type == "blog"
114+
local unreleased = is_unreleased(ref_version, branch_version)
115+
116+
if unreleased then
117+
-- Pre-release callout (both feature docs and blog)
118+
local content = md_to_blocks(
119+
"This feature is new in the upcoming Quarto " .. ref_str .. " release. " ..
120+
"To use the feature now, you'll need to " ..
121+
"[download and install](/docs/download/prerelease.qmd) " ..
122+
"the Quarto pre-release."
123+
)
124+
return quarto.Callout({
125+
type = "note",
126+
title = "Pre-release Feature",
127+
content = content,
128+
})
129+
end
130+
131+
if is_blog then
132+
-- Released blog callout
133+
local content = md_to_blocks(
134+
"This post is part of a series highlighting new features in the " ..
135+
ref_str .. " release of Quarto. Get the latest release on the " ..
136+
"[download page](/docs/download/index.qmd)."
137+
)
138+
return quarto.Callout({
139+
type = "note",
140+
title = "Quarto " .. ref_str .. " Feature",
141+
content = content,
142+
})
143+
end
144+
145+
-- Feature docs, already released: show nothing
146+
return pandoc.Blocks({})
147+
end
148+
149+
return {
150+
["prerelease-docs-url"] = docs_url_handler,
151+
["prerelease-callout"] = callout_handler,
152+
}

docs/advanced/jupyter/kernel-execution.qmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ In `python` and `julia` kernels, the setup and cleanup cells are defined by the
2525

2626
### Adding support to a Jupyter kernel
2727

28-
{{< include /docs/prerelease/1.5/_pre-release-feature.qmd >}}
28+
{{< prerelease-callout 1.5 >}}
2929

3030
If a Jupyter kernel wants to execute in awareness of Quarto's context, it should signal its support by adding the following files to the kernelspec directory:
3131

@@ -42,7 +42,7 @@ See the [source for more](https://github.com/quarto-dev/quarto_echo_kernel).
4242

4343
## Quarto document options
4444

45-
{{< include /docs/prerelease/1.5/_pre-release-feature.qmd >}}
45+
{{< prerelease-callout 1.5 >}}
4646

4747
Jupyter kernels can have access to a number of Quarto options that can affect cell execution.
4848

@@ -74,7 +74,7 @@ Quarto offers built-in support for `julia` and `python` kernels by default, see
7474

7575
### Adding support to a Jupyter kernel
7676

77-
{{< include /docs/prerelease/1.5/_pre-release-feature.qmd >}}
77+
{{< prerelease-callout 1.5 >}}
7878

7979
Arbitrary Jupyter kernels can indicate support for daemons. To do so, provide a `quarto_setup_cell` file in the kernelspec directory so that setup cells can be executed, and ensure that the execution of the setup cell returns an output result with metadata indicating support for running as a daemon. The supported metadata options are:
8080

docs/authoring/brand.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ In most cases, these assets should be committed to source control.
780780

781781
### `quarto use brand`
782782

783-
{{< include /docs/prerelease/1.9/_pre-release-feature.qmd >}}
783+
{{< prerelease-callout 1.9 >}}
784784

785785
The `quarto use brand` command copies brand files from an external source into your project's `_brand/` directory. To use it, navigate to your project directory and run:
786786

docs/authoring/diagrams.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ To include code for `{dot}`, add `//| echo: true` to the top of the cell. For ex
234234

235235
## Chrome Install {#chrome-install}
236236

237-
{{< include /docs/prerelease/1.9/_pre-release-feature.qmd >}}
237+
{{< prerelease-callout 1.9 >}}
238238

239239
For printing to output formats like `pdf` or `docx`, diagram rendering makes use of the Chrome or Edge web browser to create a high-quality PNG.
240240

docs/blog/posts/2023-03-13-code-annotation/index.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ image-alt: "Screenshot a code chunk with annotations. Annotations appear in the
1414
code-annotations: below
1515
---
1616

17-
{{< include ../_quarto-1.3-feature.qmd >}}
17+
{{< prerelease-callout 1.3 type="blog" >}}
1818

1919
Code blocks and executable code cells in Quarto may now include line-based annotations. Line-based annotations provide a way to attach explanation to lines of code much like footnotes.
2020

docs/blog/posts/2023-03-15-multi-format/index.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ format:
1717
docx: default
1818
---
1919

20-
{{< include ../_quarto-1.3-feature.qmd >}}
20+
{{< prerelease-callout 1.3 type="blog" >}}
2121

2222
Starting in Quarto 1.3, HTML pages (either standalone or in a website) can automatically include links to other formats specified in the document front matter. For example, the following document front matter:
2323

docs/blog/posts/2023-03-17-jupyter-cell-embedding/index.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ image: embed.png
1313
image-alt: "A screenshot of a Quarto page that includes a plot, below the plot is the phrase Source: penguins.ipynb."
1414
---
1515

16-
{{< include ../_quarto-1.3-feature.qmd >}}
16+
{{< prerelease-callout 1.3 type="blog" >}}
1717

1818
Starting in Quarto 1.3, you can include the output of an external Jupyter notebook in a Quarto document with the `embed` shortcode. To embed a notebook cell, provide the path to a Jupyter Notebook and a cell identifier. For example, this notebook called `penguins.ipynb` has a cell labelled `fig-bill-scatter`:
1919

0 commit comments

Comments
 (0)