# Catholic Publisher AI Editing Instructions

Give this complete file to an AI tool when you want it to update text in a
Catholic Publisher `.cpub` publication. The supported method is the companion
`cpub.exe` command-line program. Do not edit the ZIP/XML contents of a CPUB
directly.

## Objective

Use `cpub.exe` to locate one editable text target, export it as ordinary HTML,
edit that HTML, and safely create an updated CPUB. The target may be an ordinary
text box, either side of a bilingual text box, or a table cell, including a
target inside a group.

Unless the user explicitly requests an in-place update, write a new `.cpub`
file and leave the source unchanged.

## Find `cpub.exe`

The public installer normally places it here for the current Windows user:

```text
%LOCALAPPDATA%\Programs\Catholic Publisher\cpub.exe
```

In PowerShell, resolve that path with:

```powershell
$cpub = Join-Path $env:LOCALAPPDATA 'Programs\Catholic Publisher\cpub.exe'
```

For a portable or development build, `cpub.exe` is in the same folder as
`CatholicPublisher.exe`. If neither location exists, ask the user where Catholic
Publisher is installed; do not download or invent another executable.

## Required workflow

1. Ask for the source `.cpub` path and which content should change.
2. List the editable targets:

   ```powershell
   & $cpub list "C:\Publications\Bulletin YYYY-MM-DD.cpub"
   ```

3. Select the target by its unique four-character `contentId`. A `customName`
   is convenient for people but may be blank or duplicated. If a name matches
   more than one target, stop and use the exact ID.
4. Export that target:

   ```powershell
   & $cpub export "C:\Publications\Bulletin YYYY-MM-DD.cpub" --id A7K2 -o "C:\Temp\article.html"
   ```

5. Edit only the HTML body content. Preserve the two `<meta>` elements in the
   exported `<head>`; they identify the target and detect a stale source file.
6. Create a separate updated publication by default:

   ```powershell
   & $cpub replace "C:\Publications\Bulletin YYYY-MM-DD.cpub" --html "C:\Temp\article.html" -o "C:\Publications\Bulletin updated.cpub"
   ```

7. Require a successful exit code. Then open the resulting CPUB in Catholic
   Publisher and tell the user to inspect the changed text, wrapping, overflow,
   page order, and final PDF before publication.

Use `--in-place` instead of `-o` only when the user explicitly asks to update
the original file. Use `--overwrite` only when the user explicitly authorizes
replacing an existing output file.

## `list` output

`cpub list` returns JSON containing the publication path, its SHA-256, and a
`targets` array. Each target contains:

- `contentId`: unique, stable four-character identifier; prefer this selector.
- `customName`: optional human-friendly name; it is not guaranteed unique.
- `kind`: `textBox`, `bilingualEnglish`, `bilingualSpanish`, or `tableCell`.
- `page`: one-based page number.
- `objectId`: internal object GUID for diagnosis, not the normal selector.
- `row` and `column`: zero-based coordinates for table cells; otherwise null.

Images are intentionally not editable through this interface.

## HTML content format

The HTML body can replace the target with any number of paragraphs. For example:

```html
<p style="text-align:center"><strong>Parish News</strong></p>
<p>Our first paragraph has <em>italic text</em> and a manual<br>line break.</p>
<p style="text-align:justify; margin-left:0.125in; text-indent:0.25in">
  A new indented paragraph.
</p>
<ul>
  <li>First bullet</li>
  <li>Second bullet with <u>underlining</u></li>
</ul>
<ol type="a"><li>First lettered item</li><li>Second item</li></ol>
```

Supported elements:

- `<p>`: one Enter paragraph.
- `<br>`: a manual line break inside a paragraph.
- `<span>`, `<strong>`/`<b>`, `<em>`/`<i>`, `<u>`, `<sup>`, `<sub>`:
  character formatting.
- `<ul>`: a bullet-list sequence.
- `<ol>`: a decimal-numbered sequence.
- `<ol type="a">`: a lowercase-letter sequence.
- `<li>`: one paragraph in a list.

Supported character CSS:

- `font-family`
- `font-size` in `pt`
- `font-weight`
- `font-style`
- `color` as `#RRGGBB` or `#RRGGBBAA`
- `text-decoration` or `text-decoration-line` for underline
- `vertical-align: baseline | super | sub`
- `white-space: normal | pre-wrap`
- `-webkit-text-stroke-width`, `-webkit-text-stroke-color`, or
  `-webkit-text-stroke` for Catholic Publisher text outlines

Supported paragraph CSS on `<p>`, `<ul>`, `<ol>`, or `<li>`:

- `text-align: left | center | right | justify`
- `margin-left`: left indent
- `margin-right`: right indent
- `text-indent`: first-line indent; a negative value is a hanging indent
- `margin-top`: space before the paragraph
- `margin-bottom`: space after the paragraph

Paragraph lengths accept only absolute `in`, `pt`, or `px` units. Unitless zero
is also accepted. Do not use percentages, `em`, `rem`, `calc()`, positioning,
dimensions, borders, backgrounds, columns, or `line-height`.

For lists, `list-style-type` may be `disc`, `decimal`, or `lower-alpha` when it
matches the list element. Do not create nested lists, reversed lists, custom
starting numbers, unsupported marker types, or multiple block paragraphs inside
one `<li>`. Every item in one list sequence must have the same paragraph
alignment, indents, and spacing.

## Formatting and preservation rules

- Explicit HTML/CSS changes the specified formatting.
- Omitted character and paragraph properties inherit from the corresponding
  existing paragraph. Extra paragraphs inherit from the last available
  paragraph.
- Catholic Publisher's additive line-gap setting is preserved; CSS
  `line-height` is intentionally unsupported because it means something else.
- Exported lists may contain `data-cpub-list-id` and
  `data-cpub-marker-gap`. Preserve these attributes. They retain list identity
  and marker spacing when the HTML returns to the same target. An AI does not
  need to create them for a new list.
- The replacement may change the number of paragraphs and list items.
- Object geometry, content IDs, custom names, table structure, images, other
  text targets, and unrelated publication settings are preserved.

## Safety behavior

- `cpub.exe` uses the same hidden adjacent `.cpub.lock` file as Catholic
  Publisher. It refuses to write while another user or application owns the
  publication for editing.
- Exported HTML records the source SHA-256. If the CPUB changes before
  replacement, the command stops instead of applying stale HTML.
- A stale lock is not taken over unless `--take-over-stale-lock` is explicitly
  supplied. Do not use that option without confirming that nobody is editing
  the publication.
- Output is schema-validated and written atomically.
- The stored preview is removed after a successful text replacement because it
  would show the old text. Catholic Publisher recreates it on the next save.
- Never treat a command error as success, never silently select a duplicate
  custom name, and never alter another target to make an operation succeed.

For complete command syntax, run:

```powershell
& $cpub --help
```
