Fix format detection for extension format strings#14588
Merged
Conversation
Extension format strings like 'acm-pdf' are not recognized by format detection functions (isPdfOutput, isHtmlOutput, etc.) because isFormatTo uses startsWith which only matches when the base format is at the start. Includes manual test fixture from reporter's reproduction project.
isFormatTo(), isRevealjsOutput(), and isJatsOutput() used startsWith() to detect format types, which predates the extension format naming convention (<name>-<base>, e.g. acm-pdf). Extension formats put the base format at the end, not the start, so detection always returned false. Add parseFormatString() fallback when startsWith fails. This fixes format detection for all extension formats across preview (PDF.js viewer), watch (revealjs), manuscript (notebook filtering, MECA bundles), and website (HTML-first ordering) flows.
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When previewing a book project with an extension format like
dummy-extension-pdf, the preview server serves the raw PDF instead of routing through the PDF.js viewer.Root Cause
Format detection functions (
isPdfOutput,isHtmlOutput,isRevealjsOutput,isJatsOutput) usestartsWith()to match format strings against base format names. These predicates were written in 2021, before the extension format naming convention (<name>-<base>, e.g.acm-pdf) was introduced. Extension formats put the base format at the end of the string, so"acm-pdf".startsWith("pdf")always returnsfalse.Seven call sites across preview, watch, manuscript, and website flows pass raw format strings (from CLI flags or YAML keys) through these predicates, all silently returning
falsefor any extension format.Fix
Add a
parseFormatString()fallback inisFormatTo(),isRevealjsOutput(), andisJatsOutput(). When the faststartsWithcheck fails, the format string is parsed to extract its base format and re-checked. The fallback is wrapped in try/catch for malformed inputs.Test Plan
quarto previewwith extension PDF format shows PDF.js viewerquarto previewwith extension HTML format shows normal HTML (no regression)Fixes #14582