Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active September 1, 2015 23:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
<?php
/**
* Plugin Name: Listenability: Wikipedia
* Plugin URI: https://wordpress.org/plugins/listenability/
* Author: Weston Ruter
* Description: Format the text for listening (the say command).
*/
/**
* Strip out elements from Wikipedia articles.
*
* @param array $args {
* @type DOMDocument $document
* @type DOMXPath $xpath
* @type string $url
* @type array|null $readability_parser_response
* }
*/
add_action( 'listenability_document', function ( $args ) {
$is_wikipedia = ( false !== strpos( parse_url( $args['url'], PHP_URL_HOST ), 'wikipedia' ) );
if ( ! $is_wikipedia ) {
return;
}
$removed_elements = array(
'//span[@class = "mw-editsection"]',
'//sup[@class = "reference"]',
'//sup[@class = "Template-Fact"]',
'//div[@class = "reflist"]',
'//figure',
'//div[@class = "printfooter"]',
'//div[@class = "catlinks"]',
'//div[@class = "toc"]',
'//table',
);
foreach ( $args['xpath']->query( join( ' | ', $removed_elements ) ) as $element ) {
$element->parentNode->removeChild( $element );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment