protected function retrieveSectionContent( $section ) {
		if ( array_key_exists( 'raw', $section['content'] ) ) {
			$source_content = $section['content']['raw'];
		} else {
			$source_content = $section['content']['rendered'];
		}

		// According to the html5 spec section 8.3: https://www.w3.org/TR/2013/CR-html5-20130806/syntax.html#serializing-html-fragments
		// We should replace any occurrences of the U+00A0 NO-BREAK SPACE character (aka "\xc2\xa0") by the string "&nbsp;" when serializing HTML5
		// When cloning, we don't want to modify whitespaces, so we hide them from the parser.
		$characters_to_keep = [ "\xc2\xa0" ];
		foreach ( $characters_to_keep as $c ) {
			$md5 = md5( $c );
			$source_content = str_replace( $c, "<!-- pb_fixme_{$md5} -->", $source_content );
		}

		// Load source content
		$html5 = new \Pressbooks\HtmlParser();
		$dom = $html5->loadHTML( $source_content );

		// Download images, change image paths
		$media = $this->downloads->scrapeAndKneadImages( $dom );
		$dom = $media['dom'];
		$attachments = $media['attachments'];

		// Download media, change media paths
		$media = $this->downloads->scrapeAndKneadMedia( $dom, $html5->parser );
		$dom = $media['dom'];
		$attachments = array_merge( $attachments, $media['attachments'] );

		// Fix internal links
		$dom = $this->fixInternalLinks( $dom );

		// Save the destination content
		$content = $html5->saveHTML( $dom );

		// Put back the hidden characters
		foreach ( $characters_to_keep as $c ) {
			$md5 = md5( $c );
			$content = str_replace( "<!-- pb_fixme_{$md5} -->", $c, $content );
		}

		// Count attachments
		foreach ( $attachments as $pid ) {
			$this->clonedItems['media'][] = $pid;
		}

		return [ trim( $content ), $attachments ];
	}
protected function retrieveSectionContent( $section ) {
		if ( array_key_exists( 'raw', $section['content'] ) ) {
			$source_content = $section['content']['raw'];
		} else {
			$source_content = $section['content']['rendered'];
		}

		// According to the html5 spec section 8.3: https://www.w3.org/TR/2013/CR-html5-20130806/syntax.html#serializing-html-fragments
		// We should replace any occurrences of the U+00A0 NO-BREAK SPACE character (aka "\xc2\xa0") by the string "&nbsp;" when serializing HTML5
		// When cloning, we don't want to modify whitespaces, so we hide them from the parser.
		$characters_to_keep = [ "\xc2\xa0" ];
		foreach ( $characters_to_keep as $c ) {
			$md5 = md5( $c );
			$source_content = str_replace( $c, "<!-- pb_fixme_{$md5} -->", $source_content );
		}

		// Load source content
		$html5 = new \Pressbooks\HtmlParser();
		$dom = $html5->loadHTML( $source_content );

		// Download images, change image paths
		$media = $this->downloads->scrapeAndKneadImages( $dom );
		$dom = $media['dom'];
		$attachments = $media['attachments'];

		// Download media, change media paths
		$media = $this->downloads->scrapeAndKneadMedia( $dom, $html5->parser );
		$dom = $media['dom'];
		$attachments = array_merge( $attachments, $media['attachments'] );

		// Fix internal links
		$dom = $this->fixInternalLinks( $dom );

		// Save the destination content
		$content = $html5->saveHTML( $dom );

		// Put back the hidden characters
		foreach ( $characters_to_keep as $c ) {
			$md5 = md5( $c );
			$content = str_replace( "<!-- pb_fixme_{$md5} -->", $c, $content );
		}

		// Count attachments
		foreach ( $attachments as $pid ) {
			$this->clonedItems['media'][] = $pid;
		}

		return [ trim( $content ), $attachments ];
	}
protected function retrieveSectionContent ( $ section ) { if ( array_key_exists ( 'raw' , $ section [ 'content' ] ) ) { $ source_content = $ section [ 'content' ] [ 'raw' ] ; } else { $ source_content = $ section [ 'content' ] [ 'rendered' ] ; } // According to the html5 spec section 8.3: https://www.w3.org/TR/2013/CR-html5-20130806/syntax.html#serializing-html-fragments // We should replace any occurrences of the U+00A0 NO-BREAK SPACE character (aka "\xc2\xa0") by the string "&nbsp;" when serializing HTML5 // When cloning, we don't want to modify whitespaces, so we hide them from the parser. $ characters_to_keep = [ "\xc2\xa0" ] ; foreach ( $ characters_to_keep as $ c ) { $ md5 = md5 ( $ c ) ; $ source_content = str_replace ( $ c , "<!-- pb_fixme_{$md5} -->" , $ source_content ) ; } // Load source content $ html5 = new \ Pressbooks \ HtmlParser ( ) ; $ dom = $ html5 -> loadHTML ( $ source_content ) ; // Download images, change image paths $ media = $ this -> downloads -> scrapeAndKneadImages ( $ dom ) ; $ dom = $ media [ 'dom' ] ; $ attachments = $ media [ 'attachments' ] ; // Download media, change media paths $ media = $ this -> downloads -> scrapeAndKneadMedia ( $ dom , $ html5 -> parser ) ; $ dom = $ media [ 'dom' ] ; $ attachments = array_merge ( $ attachments , $ media [ 'attachments' ] ) ; // Fix internal links $ dom = $ this -> fixInternalLinks ( $ dom ) ; // Save the destination content $ content = $ html5 -> saveHTML ( $ dom ) ; // Put back the hidden characters foreach ( $ characters_to_keep as $ c ) { $ md5 = md5 ( $ c ) ; $ content = str_replace ( "<!-- pb_fixme_{$md5} -->" , $ c , $ content ) ; } // Count attachments foreach ( $ attachments as $ pid ) { $ this -> clonedItems [ 'media' ] [ ] = $ pid ; } return [ trim ( $ content ) , $ attachments ] ; }
Download media found in a section's `post_content` node, change the href links to point to newly downloaded media, etc

@param array $section

@return array{content: string, attachments: array}
Download media found in a section s post_content node change the href links to point to newly downloaded media etc