Skip to content

Fix format detection for extension format strings#14588

Merged
cderv merged 3 commits into
mainfrom
fix/issue-14582
Jun 10, 2026
Merged

Fix format detection for extension format strings#14588
cderv merged 3 commits into
mainfrom
fix/issue-14582

Conversation

@cderv

@cderv cderv commented Jun 10, 2026

Copy link
Copy Markdown
Member

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) use startsWith() 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 returns false.

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 false for any extension format.

Fix

Add a parseFormatString() fallback in isFormatTo(), isRevealjsOutput(), and isJatsOutput(). When the fast startsWith check 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

  • Unit tests pass for extension format strings across all five detectors
  • quarto preview with extension PDF format shows PDF.js viewer
  • quarto preview with extension HTML format shows normal HTML (no regression)
  • Existing preview unit tests pass (preview-compatibility, preview-initial-path, pandoc-formats)

Fixes #14582

cderv added 3 commits June 10, 2026 18:12
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.
@posit-snyk-bot

posit-snyk-bot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@cderv cderv merged commit e7f43aa into main Jun 10, 2026
49 of 51 checks passed
@cderv cderv deleted the fix/issue-14582 branch June 10, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quarto preview on book project with custom extension PDF format does not use PDF.js viewer (web/viewer.html)

2 participants