Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Varbase FAQs 9.2.1 Minor update available for module varbase_faqs (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module processes raw HTML strings to prepare them for AI systems, search indexes, or data migration. It cleans up HTML by removing unwanted elements like scripts and ads, converts relative links to absolute ones, and can optionally fetch HTML directly from a URL. The processed HTML is then minified and can be wrapped in a full document structure, resulting in cleaner, more targeted content.

What it does

Accepts an HTML string and runs it through the html_processor module's pipeline. Returns clean, narrowed HTML ready for AI systems, search indexes, or data migration.

  • Extracts specific content regions using CSS selectors (e.g. main, article, .content-body)
  • Strips unwanted markup via regex patterns (scripts, comments, tracking pixels)
  • Removes advertising elements — Google AdSense, DoubleClick, Taboola, Outbrain, Media.net, or custom patterns
  • Rewrites relative href and src attributes to absolute URLs using a caller-supplied base URL
  • Sanitizes HTML with Symfony HtmlSanitizer — configurable element and attribute allowlists, or use the safe/static shorthands
  • Wraps output in a full HTML document structure when needed
  • Minifies whitespace to reduce token count for AI pipelines

The base module processes HTML you already have in memory. For fetching HTML directly from a URL, see the URL submodule below.

URL submodule (opt-in)

document_loader_html_processor_url ships inside this package and is disabled by default. Enable it when you need the server to fetch a URL and run the returned HTML through the pipeline.

  • Fetches a URL with a single GET request via Drupal's http_client
  • Auto-injects the fetched URL as base_url so relative links resolve without extra configuration
  • Guards: scheme allowlist (http/https only), content-type check, 10 MB response cap, bounded streaming read, redirect protocol pinning, and credential-safe error messages

See the URL submodule's README.md for full security considerations and known SSRF limitations.

Use cases

  • Prepare web content for ingestion into an AI or RAG pipeline
  • Normalize HTML before search indexing
  • Extract and sanitize article bodies from scraped or migrated HTML
  • Strip ads and tracking from content before storage or republication

Requirements

This module's major version tracks Document Loader's major version — 2.x of this module requires Document Loader 2.x, 3.x will require Document Loader 3.x, and so on.

Recommended modules

  • document_loader_html_processor_url — included in this package; enable for URL fetching

Installation

composer require drupal/html_processor drupal/document_loader_html_processor

Enable at Administration > Extend. To also enable URL fetching:

drush en document_loader_html_processor_url

Configuration

The plugin appears at Administration > Configuration > Media > Document Loader. There is no per-plugin admin form — all processing options are passed programmatically.

use Drupal\document_loader_html_processor\DocumentLoaderType\Input\HtmlContentInput;

$loader = \Drupal::service('plugin.manager.document_loader')
  ->createInstance('document_loader_html_processor.html_processor');

$input = new HtmlContentInput($html, [
  'container'  => 'article',
  'remove_ads' => TRUE,
  'sanitizer'  => 'safe',
  'base_url'   => 'https://example.com/page',
]);

$processed = $loader->load($input, 'html')->getContent();

See README.md for the full options reference.

Good to know

  • No URL fetching in the base module. Pass resolved HTML via HtmlContentInput. Enable the URL submodule only when you want this module to make outbound HTTP requests.
  • No admin UI. Configuration is entirely code-driven — there are no forms to fill in.
  • SSRF limitation. The URL submodule does not filter private or internal IP ranges. Mitigate at the infrastructure layer (egress firewall, forward proxy) before exposing it to untrusted callers. See the URL submodule's README.md for details.
  • Versioning follows Document Loader. The major version of this module always matches the required major version of Document Loader.
  • Security advisory coverage. This project is not covered by Drupal's security advisory policy.

Similar projects

  • Document Loader Webpage — Readability extraction and Markdown output, not just HTML cleaning
  • HTML Processor — the standalone service module this bridge delegates to; use it directly if you do not need the Document Loader plugin layer

Activity

Total releases
4
First release
Feb 2026
Latest release
2 weeks ago
Releases (12 mo)
4 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Release date
2.0.0-rc2 Pre-release Jul 1, 2026
2.0.0-rc1 Pre-release Jun 30, 2026
1.0.0-rc1 Pre-release Feb 24, 2026
1.0.x-dev Dev Feb 24, 2026