protected function kneadHtml( $html, $type, $pos = 0 ) {

		$html5 = new HtmlParser();
		$dom = $html5->loadHTML( $html, [ 'disable_html_ns' => true ] ); // Disable default namespace for \DOMXPath compatibility

		// Download images, change to relative paths
		$dom = $this->scrapeAndKneadImages( $dom );

		// Download audio files, change to relative paths
		$dom = $this->scrapeAndKneadMedia( $dom );

		// Deal with <a href="">, <a href=''>, and other mutations
		$dom = $this->kneadHref( $dom, $type, $pos );

		// Make sure empty tags (e.g. <b></b>) don't get turned into self-closing versions by adding an empty text node to them.
		$xpath = new \DOMXPath( $dom );
		while ( ( $nodes = $xpath->query( '//*[not(text() or node() or self::br or self::hr or self::img)]' ) ) && $nodes->length > 0 ) { // @codingStandardsIgnoreLine
			foreach ( $nodes as $node ) {
				/** @var \DOMElement $node */
				$node->appendChild( new \DOMText( '' ) );
			}
		}

		// If you are storing multi-byte characters in XML, then saving the XML using saveXML() will create problems.
		// Ie. It will spit out the characters converted in encoded format. Instead do the following:
		$html = $dom->saveXML( $dom->documentElement );

		// Remove auto-created <html> <body> and <!DOCTYPE> tags.
		$html = \Pressbooks\Sanitize\strip_container_tags( $html );

		// Mobi7 hacks
		$utf8_hack = '<?xml version="1.0" encoding="UTF-8"?>';
		$html = $this->transformXML( "{$utf8_hack }<html>{$html}</html>", $this->dir . '/templates/epub201/mobi-hacks.xsl' );

		return $html;
	}
protected function kneadHtml( $html, $type, $pos = 0 ) {

		$html5 = new HtmlParser();
		$dom = $html5->loadHTML( $html, [ 'disable_html_ns' => true ] ); // Disable default namespace for \DOMXPath compatibility

		// Download images, change to relative paths
		$dom = $this->scrapeAndKneadImages( $dom );

		// Download audio files, change to relative paths
		$dom = $this->scrapeAndKneadMedia( $dom );

		// Deal with <a href="">, <a href=''>, and other mutations
		$dom = $this->kneadHref( $dom, $type, $pos );

		// Make sure empty tags (e.g. <b></b>) don't get turned into self-closing versions by adding an empty text node to them.
		$xpath = new \DOMXPath( $dom );
		while ( ( $nodes = $xpath->query( '//*[not(text() or node() or self::br or self::hr or self::img)]' ) ) && $nodes->length > 0 ) { // @codingStandardsIgnoreLine
			foreach ( $nodes as $node ) {
				/** @var \DOMElement $node */
				$node->appendChild( new \DOMText( '' ) );
			}
		}

		// If you are storing multi-byte characters in XML, then saving the XML using saveXML() will create problems.
		// Ie. It will spit out the characters converted in encoded format. Instead do the following:
		$html = $dom->saveXML( $dom->documentElement );

		// Remove auto-created <html> <body> and <!DOCTYPE> tags.
		$html = \Pressbooks\Sanitize\strip_container_tags( $html );

		// Mobi7 hacks
		$utf8_hack = '<?xml version="1.0" encoding="UTF-8"?>';
		$html = $this->transformXML( "{$utf8_hack }<html>{$html}</html>", $this->dir . '/templates/epub201/mobi-hacks.xsl' );

		return $html;
	}
protected function kneadHtml ( $ html , $ type , $ pos = 0 ) { $ html5 = new HtmlParser ( ) ; $ dom = $ html5 -> loadHTML ( $ html , [ 'disable_html_ns' => true ] ) ; // Disable default namespace for \DOMXPath compatibility // Download images, change to relative paths $ dom = $ this -> scrapeAndKneadImages ( $ dom ) ; // Download audio files, change to relative paths $ dom = $ this -> scrapeAndKneadMedia ( $ dom ) ; // Deal with <a href="">, <a href=''>, and other mutations $ dom = $ this -> kneadHref ( $ dom , $ type , $ pos ) ; // Make sure empty tags (e.g. <b></b>) don't get turned into self-closing versions by adding an empty text node to them. $ xpath = new \ DOMXPath ( $ dom ) ; while ( ( $ nodes = $ xpath -> query ( '//*[not(text() or node() or self::br or self::hr or self::img)]' ) ) && $ nodes -> length > 0 ) { // @codingStandardsIgnoreLine foreach ( $ nodes as $ node ) { /** @var \DOMElement $node */ $ node -> appendChild ( new \ DOMText ( '' ) ) ; } } // If you are storing multi-byte characters in XML, then saving the XML using saveXML() will create problems. // Ie. It will spit out the characters converted in encoded format. Instead do the following: $ html = $ dom -> saveXML ( $ dom -> documentElement ) ; // Remove auto-created <html> <body> and <!DOCTYPE> tags. $ html = \ Pressbooks \ Sanitize \ strip_container_tags ( $ html ) ; // Mobi7 hacks $ utf8_hack = '<?xml version="1.0" encoding="UTF-8"?>' ; $ html = $ this -> transformXML ( "{$utf8_hack }<html>{$html}</html>" , $ this -> dir . '/templates/epub201/mobi-hacks.xsl' ) ; return $ html ; }
Pummel the HTML into EPUB compatible dough.

@param string $html
@param string $type front-matter, part, chapter, back-matter, ...
@param int $pos (optional) position of content, used when creating filenames like: chapter-001, chapter-002, ...

@return string
Pummel the HTML into EPUB compatible dough .