Problem/Motivation
Rendered node markup carries extra code and content that doesn't belong in an ebook: internal-note fields, related-content sidebars, callouts, and other theme output. The sanitizer already removes known Drupal markup (contextual links, tabs, book navigation), but there's no way to remove anything site-specific short of building a dedicated ePub view mode for every content type.
Steps to reproduce
- Add a field or block to a book content type that renders in the ePub view mode (e.g. an internal-notes field or an
<aside>of related links). - Generate a book.
- The unwanted markup appears in the ePub with no setting to exclude it.
Proposed resolution
Add a strip-selectors setting: CSS selectors, one per line, whose matching elements are removed from every generated ePub, on top of the built-in Drupal markup removal. Add a matching per-book field that appends to the site-wide list.
Translate the selectors to XPath with a small in-module converter rather than requiring symfony/css-selector, which is a dev-only dependency of core and would break tarball installs. Support type, class, id, and attribute selectors with descendant and child combinators; pass raw XPath through; reject unsupported syntax (pseudo-classes, sibling combinators) at validation time so a bad selector can't silently match the wrong nodes.
Remaining tasks
- Review
- Test coverage for the selector translator and the strip pass
User interface changes
New "Strip selectors" textarea on the main settings form. New "Strip selectors" field on book root nodes, with a matching entry in the field mapping form.
API changes
HtmlToXhtmlSanitizer::sanitize() gains an optional $stripSelectors argument. EpubGeneratorService::generate() accepts a strip_selectors option. New CssSelectorToXPath utility class. All additions are backward compatible.
Data model changes
New strip_selectors sequence in epub_generator.settings. On the book side, a strip_selectors mapping key and the field_epub_strip_selectors field. Update hooks seed both keys on existing installs.
Issue fork epub_generator-3613628
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
andileco commentedComment #5
andileco commented