Filters enable solving noise issues in versions that cannot be addressed with direct selection or removal of content using selectors.
Use filters when:
select
and remove
properties.Filters are JavaScript functions that can manipulate the DOM structure directly. They modify the document structure and content in-place.
Filters should follow these core principles:
Specific: target only the noise to remove. Avoid broad selectors that might accidentally remove important content.
For example, if a filter converts relative dates to absolute dates, make sure to scope the targeted dates. This might translate to selecting with
.metadata time
, nottime
, which might also affect important effective dates within the terms content.
Idempotent: filters should produce the same result even if run multiple times on their own output. This ensures consistency.
For example, if a filter adds section numbers like “1.” to headings, it should check if the numbers already exist, to prevent “1. Privacy Policy” from becoming “1. 1. Privacy Policy” on repeated runs.
Efficient: DOM queries should be optimised and filters should avoid unnecessary operations, processing only the elements needed.
For example, if a filter updates timestamp elements with a specific class, using
document.querySelectorAll('.timestamp')
is more efficient thandocument.querySelectorAll('*')
followed by filtering for timestamp elements.
Safe: filters must not accidentally remove important content. The generated version should always be checked after adding a filter to ensure it still contains the whole terms content.