Edit Spans & Divs helps remove, strip, or retag selected XHTML elements without manually writing transform rules. It is designed for quick one-off cleanup during Calibre Edit Book work.
Use the toolbar menu to choose whether the operation applies only to the current XHTML file or to every XHTML file in the book. Start with the current file when testing a new rule.
Choose a tag name, choose Any tag to search across all tags, or choose Custom tag to type an exact tag name that is not in the shortcut list. Then choose whether to match elements with a specific attribute, any attribute, or no attributes. The With contents field can be matched exactly or treated as a regular expression.
With contents is matched against attribute values, not against the text inside the element. For example, entering chapter matches <section class="chapter">, but it does not match <section>Chapter One</section>. There is no option to select elements by their visible text.
Any attribute with blank contents matches tags that have at least one attribute, regardless of name or value. Any attribute with contents entered matches tags where any attribute value equals or regex-matches that content. No attributes matches only naked tags. Shortcut tag names and shortcut attribute names are convenience lists; custom tag mode allows advanced users to target unlisted tags.
Examples of common searches:
span with class="italic"
div with no attributes
p with a class value matching a regular expression
section with any attribute, regardless of whether it uses class, id, role, or epub:type
section with any attribute and contents matching chapter
Any tag with any attribute and contents matching chapter
Custom tag with a typed tag name such as aside or hgroup
section with Custom attribute set to epub:type and contents matching chapter
Delete unwraps the selected element while preserving its text, child elements, and tail text where possible.
Example:
<span class="x">Hello</span>
can become:
Hello
Selecting a tag with No attributes and deleting it is a quick way to remove naked wrapper elements left behind by conversion. Note that a bare <span> or <div> can still carry meaning if a stylesheet targets the element type itself, so review the diff rather than assuming such elements are always redundant.
Strip attributes removes attributes from matching elements while keeping the element itself. The strip mode can remove all attributes, or remove only a custom comma-separated list of attribute names and wildcard patterns.
Custom examples include class, id, style, aria-*, data-*, and epub:*. Wildcards use simple * matching, not regular expressions.
Example:
<span class="x" id="y">Hello</span>
can become:
<span>Hello</span>
Modify can change the selected tag to another tag and control how attributes are handled. Attribute handling can keep existing attributes, replace all attributes with a new attribute string, or add/update only the attributes named in the supplied string.
In add/update mode, unspecified attributes are preserved. If the supplied attribute string names an attribute that already exists, the existing value is replaced.
Examples:
<i> to <em>.
<b> to <strong>.
<div> to <p> or <blockquote>.
Attribute strings should be entered as space-separated name-value pairs, for example class="chapter-title" id="ch1". Change tag to Custom tag lets you type an unlisted replacement tag. The tool validates tag-name syntax but does not validate whether the chosen tag and attributes are semantically appropriate.
The Customize dialog lets you edit the shortcut lists of offered tags, editable attributes, and per-tag conversion choices. These lists are conveniences, not hard limits: use Custom tag or Custom attribute for one-off unlisted names. Add a tag to the tag list, rebuild the tag rows, then set the allowed conversion targets for that tag.
The top-right question-mark button opens a short customization reminder. The change-to mapping area is arranged in compact columns. Each column contains ten tag rows, then additional rows continue in the next column. The reload button beside a mapping restores the default mapping for that tag.
Use Backup settings... to save the current shortcut tag list, shortcut attribute list, and per-tag *_changes mappings to a JSON file. The backup includes values currently shown in the dialog, so it can recover an accidental reset or transfer customizations to another installation.
Use Import settings... to import either an Otter Span/Div backup or a compatible Diap's Editing Toolbag Span/Div settings JSON file. Imported tags, attributes, and mappings are merged with the current settings. Newer Otter runtime options such as Any tag, Custom tag, Any attribute, Custom attribute, and Strip attributes modes are built into the interface and are not part of the imported lists.
Reset buttons are available for the visible tag and attribute lists or all Span/Div defaults.
Structural document tags are protected from deletion. Protected tags include html, head, body, title, meta, link, script, and style.
This tool can change many files quickly. After processing, use the changed-files dialog and Calibre's diff viewer to verify that the selected rule matched only the intended markup.