Skip to content

Commit 664486a

Browse files
authored
fix: resolve extension language and metadata files from the document (#15274)
A format extension's `language` and `metadata-files` now resolve inside the extension directory. The format was resolved against the parent of that directory, so the render failed on a `language` file that existed, and `metadata-files` were silently skipped. The paths in `_extension.yml` are already rewritten relative to the document, so the format now resolves from the document too, using the same base. - Resolve the extension format from the document path, not the extension directory - Add smoke tests for per-language files, organisation directories, subfolders, document overrides, `metadata-files`, and projects Fixes #15063
1 parent 53de911 commit 664486a

25 files changed

Lines changed: 196 additions & 1 deletion

‎news/changelog-1.12.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ All changes included in 1.12:
1818
- ([#14783](https://github.com/quarto-dev/quarto-cli/issues/14783)): Fix `quarto preview` ignoring project metadata contributed by an extension, such as `brand`. Contributed project metadata now applies to every command that builds a project context, `quarto inspect` included. (author: @mcanouil)
1919
- ([#15266](https://github.com/quarto-dev/quarto-cli/issues/15266)): Fix `quarto preview` keeping the project metadata an extension contributed at startup, such as `brand`, after its `_extension.yml` changes.
2020

21+
## Extensions
22+
23+
- ([#15063](https://github.com/quarto-dev/quarto-cli/issues/15063)): Fix a format extension's own `language` file stopping the render with a "does not exist" error, and its `metadata-files` being ignored. Both now resolve relative to the extension's directory, and per-language files such as `_language-fr.yml` load beside the `language` file. (author: @mcanouil)
24+
2125
## Other fixes and improvements
2226

2327
- ([#14822](https://github.com/quarto-dev/quarto-cli/issues/14822)): Translate the `tools-share`, `tools-download`, and `skip-to-content` language keys in Greek. (author: @sogav21)

‎src/command/render/render-contexts.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,11 @@ const readExtensionFormat = async (
717717
extensionMetadata[kExtensionName] = extensionMetadata[kExtensionName] ||
718718
effectiveExtension;
719719

720+
// resolveExtensionPaths made the extension paths relative to the
721+
// document, so the document is the base, not the extension directory
720722
const formats = await resolveFormatsFromMetadata(
721723
extensionMetadata,
722-
extension.path,
724+
file,
723725
[formatDesc.baseFormat],
724726
);
725727

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.quarto/
2+
**/*.quarto_ipynb
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title: Language file
2+
author: Quarto Dev Team
3+
version: 1.0.0
4+
contributes:
5+
formats:
6+
html:
7+
language: _language.yml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
toc-title-document: "Sommaire de l extension"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
toc-title-document: "Contents from the extension"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project:
2+
type: default
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: "A document in a project subdirectory reads the language file of a root extension"
3+
format: langfile-html
4+
toc: true
5+
_quarto:
6+
tests:
7+
langfile-html:
8+
ensureFileRegexMatches:
9+
- ['<h2 id="toc-title">Contents from the extension</h2>']
10+
- []
11+
---
12+
13+
## Section
14+
15+
This document is in a subdirectory of the project, and the `langfile` extension is at the root of the project.
16+
The path to the language file of the extension starts with `../`.
17+
Before the fix, this case worked by chance, because the wrong base directory and the `../` offset cancelled each other out.
18+
This test makes sure that the case continues to work.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: "A format extension at the project root reads its own language file"
3+
format: langfile-html
4+
toc: true
5+
_quarto:
6+
tests:
7+
langfile-html:
8+
ensureFileRegexMatches:
9+
- ['<h2 id="toc-title">Contents from the extension</h2>']
10+
- []
11+
---
12+
13+
## Section
14+
15+
This document is at the root of a project, and the `langfile` extension is in the `_extensions/` directory of the project.
16+
Before the fix, Quarto looked for the language file in `_extensions/_extensions/langfile/` and the render stopped.
17+
The table of contents must show the title from the language file of the extension.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title: Language file in an organisation
2+
author: Quarto Dev Team
3+
version: 1.0.0
4+
contributes:
5+
formats:
6+
html:
7+
language: _language.yml

0 commit comments

Comments
 (0)