Skip to content

Keep inferred document titles free of smart punctuation - #105

Merged
odrobnik merged 1 commit into
mainfrom
fix/title-smart-punctuation
Sep 15, 2026
Merged

odrobnik merged 1 commit into
mainfrom
fix/title-smart-punctuation

Conversation

@odrobnik

Copy link
Copy Markdown
Contributor

Problem

cmark-gfm applies smart punctuation by default — typed --, ---, ... and straight quotes become en/em dashes, an ellipsis and curly quotes. SwiftMarkdownHTMLRenderer documents the project's policy of literal source fidelity and every renderer parses with .disableSmartOpts to enforce it.

MarkdownToHTML.firstHeadingPlainText was the only Document(parsing:) call site in the package that passed no options — 1 of 12.

That function is what RenderCommand.inferTitle uses to derive the document title, so a heading containing -- or ... produced a title with typographic substitution while the body under it kept the literal source:

title: Dashes – and ellipsis… and “quotes”
body:  <p>Body -- text... here.</p>

The mismatch reached the HTML <title> and the title metadata written into PDF, DOCX and EPUB output.

Fix

Pass .disableSmartOpts at that call site too, matching the other eleven.

Verification

After the fix, all three agree:

<title>Dashes -- and ellipsis... and "quotes"</title>
<p>Body -- text... here.</p>
PDF /Title = Dashes -- and ellipsis... and "quotes"

Added firstHeadingPlainTextKeepsLiteralPunctuation, which pins the title and the rendered body to the same convention and rejects all seven smart characters. Verified non-vacuous — reverting just the parse option fails it with 5 issues.

Full suite: 582 tests in 63 suites passing; swiftlint --strict clean.

Provenance

Found while auditing stale branches for unmerged work. An abandoned branch carried a reverseSmartPunctuation helper absent from main; tracing why showed main had solved the problem better — by disabling the substitution rather than reversing it after the fact — and that one call site had been missed.

🤖 Generated with Claude Code

cmark-gfm applies smart punctuation by default, turning typed `--`,
`---`, `...` and straight quotes into dashes, an ellipsis and curly
quotes. SwiftMarkdownHTMLRenderer documents the project's policy of
literal source fidelity and every renderer parses with
`.disableSmartOpts` to enforce it — except firstHeadingPlainText, the
one Document(parsing:) call site in the package that passed no options.

That function is what RenderCommand.inferTitle uses to derive a
document title, so a heading containing `--` or `...` produced a title
with typographic substitution while the body under it kept the literal
source:

    title: Dashes – and ellipsis… and “quotes”
    body:  <p>Body -- text... here.</p>

The mismatch reached the HTML <title> and the title metadata written
into PDF, DOCX and EPUB output.

Pass `.disableSmartOpts` here too, and add a regression test pinning the
title and the rendered body to the same convention.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-15T13:06:22.885548Z 82d7594 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@odrobnik
odrobnik merged commit 03b9ff0 into main Sep 15, 2026
7 checks passed
@odrobnik
odrobnik deleted the fix/title-smart-punctuation branch September 15, 2026 13:20
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.

1 participant