Cleanup

Cleanup performs common editorial corrections to the text of a book: apostrophes, ellipses, dashes, and prose whitespace. Each group can be enabled or disabled on its own, so you can run only the corrections a book actually needs.

Current file or whole book

Use the toolbar menu to choose whether Cleanup processes only the current XHTML file or every XHTML file in the book. Whole-book runs skip navigation and table-of-contents documents. Start with the current file when trying out new settings.

Repair suspect quotes

Repair suspect quotes is off by default and independent of every other option on this dialog. With it unticked, Cleanup never converts a straight quotation mark and never rewrites an ordinary contraction apostrophe — apostrophe exception rules and abbreviated-year fixes are unaffected either way, since those are controlled separately below.

Ticking it lightly repairs objectively suspect quote forms — opening single quotes used inside words, malformed abbreviated-year apostrophes, grave or acute accents used as quote substitutes, contradictory double-quote forms — and then reprocesses the affected text through the same quote-smartening logic Smarten Punctuation uses. It does not try to infer authorial intent or rebalance dialogue, and it does not perform an initial straight-to-curly smartening pass on otherwise undamaged quotes: use Smarten Punctuation for that. This option is for repairing quotes that were already smartened and then damaged by further hand-editing, OCR, or a prior import.

Only quote marks with something objectively suspect about them are re-smartened. Plain, already-correct straight or curly quotes elsewhere in the text are left untouched even with this option ticked — so ticking it on a book with no damaged quotes can leave the quote-related text completely unchanged, and that is expected behaviour, not a sign that the option had no effect.

Apostrophe cleanup

Enable apostrophe cleanup is the master switch for this group. When it is unticked, Cleanup leaves apostrophes alone and you can run ellipsis, dash, or whitespace cleanup on their own.

With the group enabled, Cleanup fixes abbreviated year apostrophes, so class of '79, '68 Mustang, and '90s become class of ’79, ’68 Mustang, and ’90s.

Apply apostrophe exception rules additionally applies an exception file, shared with Smarten Punctuation, for project-specific words the smartening engine would otherwise get wrong. Rules are explicit mappings:

@em -> ’em
@tis -> ’tis
rock @n@ roll -> rock ’n’ roll

The @ marker means an apostrophe must already be present in the source at that position. So @em -> ’em fixes 'em, ‘em, and ’em, but leaves the plain word em untouched. Matching is case-insensitive, and the original letter case is preserved.

Ellipsis cleanup

Cleanup recognises compact and spaced-dot ellipses such as ..., . . ., ...., and . . . ., and converts them to a single, consistent form: either the ellipsis character …, or a spaced-period form (. . .) using non-breaking spaces between the periods, depending on the spacing style selected below.

The spacing style controls the final form:

Four-dot ellipses

Four-dot forms can be converted to a single ellipsis, converted to an ellipsis plus a period, or preserved. Preserve them when the source deliberately distinguishes a sentence-ending ellipsis from trailing hesitation.

Attachment markers

Some books already contain invisible characters that bind punctuation to the neighbouring word. This setting is separate from the visible spacing style.

Parenthetical dash normalization

Existing em and en dashes used parenthetically can be preserved, or normalized to one of:

Hyphens are never converted, and closed range or connection en dashes such as 10–50 and London–Glasgow are left alone. A dash is respaced only when there is visible text on both sides of it, so decorative separator lines and dashes that open a line of dialogue are not altered.

Dashes that fall between inline elements are handled too, so <em>word</em> — <em>word</em> is respaced in the same way as a dash in ordinary prose.

Convert existing dashes between em and en styles lets the dash style above also convert dashes belonging to the other family, rather than only re-spacing dashes that already match the selected style. For example, with Em dash selected, an existing spaced en dash (word – word) is converted to an em dash as well; with British open en dash selected, an existing em dash (open or closed) is converted to an open en dash.

A closed, unspaced en dash such as 10–50 or Mexico–United States is never touched by this option, in either direction. It cannot reliably be told apart from a numeric range or a compound connector, so a genuinely misused closed en dash is left for manual correction rather than automated conversion. An en dash is only ever treated as a conversion source when it already has recognised spacing on at least one side; a bare em dash carries no such ambiguity and is recognised as a source regardless of spacing. This option is off by default.

Attachment markers

Attachment spacing

Where Cleanup attaches punctuation to the preceding word, this setting chooses the characters used. Each profile is a pair: a non-breaking space before the mark, so it cannot be orphaned onto a new line, and an ordinary breaking space after it, so the line can still wrap.

The setting applies to the ellipsis styles Attach ellipsis to the preceding word and Periods separated by non-breaking space, and to the dash setting Attach open-spaced dashes. It is greyed out when none of these is selected. The ellipsis and dash style settings remain independent of each other, so a book can have tight ellipses and spaced dashes.

Whitespace normalization

Adjacent nested quotation marks

When a quotation opens or closes inside another quotation, the two marks can sit uncomfortably close together. Separate adjacent nested quotation marks enables two settings.

Insert chooses what separates the pair: no space, a narrow no-break space, or a no-break space. Only non-breaking characters are offered, because a line must never break between two nested quote marks.

Existing spacing decides what happens where a gap is already present:

Only unlike opening or closing quote pairs are affected. Ordinary prose spacing and identical quote pairs are left alone.

Unwrap hard-wrapped paragraphs

This option joins single source line breaks inside paragraph text, including text nested in inline elements such as <p><i>wrapped text</i></p>. Blank-line paragraph boundaries are not joined.

Output

Use unicode characters instead of entities writes punctuation as real characters such as “, ’, —, and …. Untick it to write numeric character references instead, for projects that require them. Text you have deliberately escaped in the source is never converted either way.

Allow XHTML markup normalization when saving permits the XML serializer's normalized output, which can render an empty tag pair such as <a></a> as <a/>. Leave it unticked to keep the book's original markup style. This is separate from Calibre's Beautify tool.

Reviewing changes

Cleanup makes editorial changes to finished text. A savepoint is created before processing, and the changed-files dialog offers Calibre's diff viewer afterwards. Tick Repair suspect quotes when a book's quotation marks show visible damage; leave it off for routine production work on a book whose quotes are already correct, and always review the diff.