Yields an estimated percentage slice of: 50-60

@param array $book_contents
@param array $metadata
@return \Generator
764684
protected function createBackMatterGenerator( $book_contents, $metadata ) : \Generator {
		$back_matter_printf = '<div class="back-matter %1$s" id="%2$s">';
		$back_matter_printf .= '<div class="back-matter-title-wrap"><h3 class="back-matter-number">%3$s</h3><h1 class="back-matter-title">%4$s</h1>%5$s</div>';
		$back_matter_printf .= '<div class="ugc back-matter-ugc">%6$s</div>%7$s';
		$back_matter_printf .= '</div>';

		$y = new PercentageYield( 50, 70, count( $book_contents['back-matter'] ) );

		$vars = [
			'post_title' => '',
			'stylesheet' => $this->stylesheet,
			'post_content' => '',
			'append_back_matter_content' => '',
			'isbn' => ( isset( $metadata['pb_ebook_isbn'] ) ) ? $metadata['pb_ebook_isbn'] : '',
			'lang' => $this->lang,
		];

		$i = 1;
		foreach ( $book_contents['back-matter'] as $back_matter ) {
			yield from $y->tick( $this->generatorPrefix . __( 'Exporting back matter', 'pressbooks' ) );

			if ( ! $back_matter['export'] ) {
				continue; // Skip
			}

			$back_matter_id = $back_matter['ID'];
			$subclass = $this->taxonomy->getBackMatterType( $back_matter_id );
			$slug = $back_matter['post_name'];
			$title = ( get_post_meta( $back_matter_id, 'pb_show_title', true ) ? $back_matter['post_title'] : '' );
			$after_title = '';
			$content = $this->kneadHtml( $back_matter['post_content'], 'back-matter', $i );
			$append_back_matter_content = $this->kneadHtml( apply_filters( 'pb_append_back_matter_content', '', $back_matter_id ), 'back-matter', $i );
			$short_title = trim( get_post_meta( $back_matter_id, 'pb_short_title', true ) );
			$subtitle = trim( get_post_meta( $back_matter_id, 'pb_subtitle', true ) );
			$author = $this->contributors->get( $back_matter_id, 'pb_authors' );

			if ( Export::shouldParseSubsections() === true ) {
				if ( Book::getSubsections( $back_matter_id ) !== false ) {
					$content = Book::tagSubsections( $content, $back_matter_id );
					$content = $this->html5ToXhtml( $content );
				}
			}

			if ( $author ) {
				if ( $this->wrapHeaderElements ) {
					$after_title = '<h2 class="chapter-author">' . Sanitize\decode( $author ) . '</h2>' . $after_title;
				} else {
					$content = '<h2 class="chapter-author">' . Sanitize\decode( $author ) . '</h2>' . $content;
				}
			}

			if ( $subtitle ) {
				if ( $this->wrapHeaderElements ) {
					$after_title = '<h2 class="chapter-subtitle">' . Sanitize\decode( $subtitle ) . '</h2>' . $after_title;
				} else {
					$content = '<h2 class="chapter-subtitle">' . Sanitize\decode( $subtitle ) . '</h2>' . $content;
				}
			}

			if ( $short_title ) {
				if ( $this->wrapHeaderElements ) {
					$after_title = '<h6 class="short-title">' . Sanitize\decode( $short_title ) . '</h6>' . $after_title;
				} else {
					$content = '<h6 class="short-title">' . Sanitize\decode( $short_title ) . '</h6>' . $content;
				}
			}

			$section_license = $this->doSectionLevelLicense( $metadata, $back_matter_id );
			if ( $section_license ) {
				$append_back_matter_content .= $this->kneadHtml( $this->tidy( $section_license ), 'back-matter', $i );
			}

			$vars['post_title'] = $back_matter['post_title'];
			$vars['post_content'] = sprintf(
				$back_matter_printf,
				$subclass,
				$slug,
				$i,
				Sanitize\decode( $title ),
				$after_title,
				$content,
				$var['append_back_matter_content'] = $append_back_matter_content,
				''
			);

			$file_id = 'back-matter-' . sprintf( '%03s', $i );
			$filename = "{$file_id}-{$slug}.{$this->filext}";

			\Pressbooks\Utility\put_contents(
				$this->tmpDir . "/OEBPS/$filename",
				$this->loadTemplate( $this->dir . '/templates/epub201/html.php', $vars )
			);

			$this->manifest[ $file_id ] = [
				'ID' => $back_matter['ID'],
				'post_title' => $back_matter['post_title'],
				'filename' => $filename,
			];

			++$i;
		}

	}
574423
public function getSummaryAttribute()
    {
        $excerpt = $this->excerpt;
        if (strlen(trim($excerpt))) {
            return $excerpt;
        }

        $more = '<!-- more -->';
        if (strpos($this->content_html, $more) !== false) {
            $parts = explode($more, $this->content_html);

            return array_get($parts, 0);
        }

        return Html::limit($this->content_html, 600);
    }
978894
public function prepareMetaDescriptionForPersist($meta_description="", $excerpt)
    {
        if ($meta_description == "") return $excerpt;

        $meta_description = html_entity_decode($meta_description);
        $meta_description = strip_tags($meta_description);
        $meta_description = filter_var($meta_description, FILTER_SANITIZE_STRING);

        // remove the encoded blank chars
        $meta_description = str_replace("\xc2\xa0",'',$meta_description);

        $meta_description = trim($meta_description);
        return $meta_description;
    }
907029
protected function cloneMetadata() {
		$metadata_post_id = ( new \Pressbooks\Metadata )->getMetaPostId();

		if ( ! $metadata_post_id ) {
			return false;
		}

		$book_information = schema_to_book_information( $this->sourceBookMetadata );

		// Cover image
		if ( ! \Pressbooks\Image\is_default_cover( $book_information['pb_cover_image'] ) ) {
			$new_cover_id = $this->downloads->fetchAndSaveUniqueImage( $book_information['pb_cover_image'] );
			if ( $new_cover_id > 0 ) {
				$this->clonedItems['media'][] = $new_cover_id; // Counter
				$book_information['pb_cover_image'] = wp_get_attachment_url( $new_cover_id );
			} else {
				$book_information['pb_cover_image'] = default_cover_url();
			}
		} else {
			$book_information['pb_cover_image'] = default_cover_url();
		}

		// Everything else
		$book_information['pb_is_based_on'] = $this->sourceBookUrl;
		$metadata_array_values = [ 'pb_keywords_tags', 'pb_bisac_subject', 'pb_additional_subjects' ];
		foreach ( $book_information as $key => $value ) {
			if ( $this->contributors->isValid( $key ) ) {
				$values = oxford_comma_explode( $value );
				foreach ( $values as $v ) {
					$this->contributors->insert( $v, $metadata_post_id, $key );
				}
			} elseif ( in_array( $key, $metadata_array_values, true ) ) {
				$values = explode( ', ', $value );
				foreach ( $values as $v ) {
					add_post_meta( $metadata_post_id, $key, $v );
				}
			} elseif ( $key === 'pb_title' ) {
				update_post_meta( $metadata_post_id, $key, $this->targetBookTitle );
			} else {
				update_post_meta( $metadata_post_id, $key, $value );
				if ( $key === 'pb_book_license' ) {
					wp_set_object_terms( $metadata_post_id, $value, \Pressbooks\Licensing::TAXONOMY ); // Link
				}
			}
		}

		// Remove the current user from the author field in Book Info
		$user_data = get_userdata( get_current_user_id() );
		$this->contributors->unlink( $user_data->user_nicename, $metadata_post_id );

		return $metadata_post_id;
	}
336348
static function wordCount( $selected_for_export = false ) {
		$wc = 0;
		$wc_selected_for_export = 0;
		foreach ( static::getBookStructure() as $key => $section ) {
			if ( $key === 'front-matter' || $key === 'back-matter' ) {
				foreach ( $section as $val ) {
					$wc += $val['word_count'];
					if ( $val['export'] ) {
						$wc_selected_for_export += $val['word_count'];
					}
				}
			}
			if ( $key === 'part' ) {
				foreach ( $section as $part ) {
					foreach ( $part['chapters'] as $val ) {
						$wc += $val['word_count'];
						if ( $val['export'] ) {
							$wc_selected_for_export += $val['word_count'];
						}
					}
				}
			}
		}

		return $selected_for_export ? $wc_selected_for_export : $wc;
	}
323099
def _generate(self):
        """"""
        doc_count = 0
        for fp in self.all_files:
            for doc in self._get_docs_for_path(fp):
                yield doc
                doc_count += 1
                if doc_count >= self.max_docs:
                    return
449587
public static function percentageWordsWithThreeSyllables($strText, $blnCountProperNouns = true, $strEncoding = '')
    {
        $intWordCount = Text::wordCount($strText, $strEncoding);
        $intLongWordCount = self::wordsWithThreeSyllables($strText, $blnCountProperNouns, $strEncoding);
        $intPercentage = Maths::bcCalc(Maths::bcCalc($intLongWordCount, '/', $intWordCount), '*', 100);

        return $intPercentage;
    }
316539
public void extract(@NotNull final RandomAccessReader reader, @NotNull final Metadata metadata)
    {
        extract(reader, metadata, 0);
    }
1323405
protected function bookHtmlError( $book_html ) {

		$message = "ICML conversion returned a file of zero bytes. \n";
		$message .= 'This usually happens when bad XHTML (I.e. $book_html) is passed to the XSL transform routine. ' . "\n";
		$message .= 'Analysis of $book_html follows: ' . "\n\n";

		$book_html_path = $this->createTmpFile();
		\Pressbooks\Utility\put_contents( $book_html_path, $book_html );

		// Xmllint params
		$command = PB_XMLLINT_COMMAND . ' --html --valid --noout ' . escapeshellcmd( $book_html_path ) . ' 2>&1';

		// Execute command
		$output = [];
		$return_var = 0;
		exec( $command, $output, $return_var );

		return $message . implode( "\n", $output );
	}
641565
def binarycontent_sections(chunk):
    ''''''
    # using string split because it is significantly faster than regex.

    # use common text of start and end tags to split the text
    # (i.e. without < or </ tag beginning)
    binary_content_tag = BINARY_CONTENT_START[1:]
    if binary_content_tag not in chunk:
        # if no tags are present, don't do any extra work
        yield chunk

    else:
        # split on common portion of foxml:binaryContent
        sections = chunk.split(binary_content_tag)
        for sec in sections:
            extra = b''
            # check the end of the section to determine start/end tag
            if sec.endswith(b'</'):
                extra = sec[-2:]
                yield sec[:-2]

            elif sec.endswith(b'<'):
                extra = sec[-1:]
                yield sec[:-1]

            else:
                yield sec

            if extra:
                # yield the actual binary content tag
                # (delimiter removed by split, but needed for processing)
                yield b''.join([extra, binary_content_tag])
1232818
public function isDocumentTranslatable(ClassMetadata $metadata)
    {
        return !empty($metadata->translator)
            && is_string($metadata->translator)
            && count($metadata->translatableFields) !== 0;
    }
833106
public void extract(@NotNull final SequentialReader reader, @NotNull final Metadata metadata, long length)
    {
        extract(reader, metadata, length, null);
    }
52881
public static function getRangeInfo(string $isbn) : ?RangeInfo
    {
        $length = strlen($isbn);
        $isbnPrefix = ($length === 10) ? '978' : substr($isbn, 0, 3);
        $isbnDigits = ($length === 10) ? $isbn : substr($isbn, 3);

        foreach (self::getRanges() as $rangeData) {
            list ($eanPrefix, $groupIdentifier, $groupName, $ranges) = $rangeData;

            if ($isbnPrefix !== $eanPrefix) {
                continue;
            }

            $groupLength = strlen($groupIdentifier);
            $isbnGroup = substr($isbnDigits, 0, $groupLength);

            if ($isbnGroup !== $groupIdentifier) {
                continue;
            }

            $rangeInfo = new RangeInfo;
            $rangeInfo->groupIdentifier = ($length === 10 ? $groupIdentifier : $eanPrefix . '-' . $groupIdentifier);
            $rangeInfo->groupName = $groupName;

            foreach ($ranges as $range) {
                list ($rangeLength, $rangeStart, $rangeEnd) = $range;
                $rangeValue = substr($isbnDigits, $groupLength, $rangeLength);
                $lastDigits = substr($isbnDigits, $groupLength + $rangeLength, -1);
                $checkDigit = substr($isbnDigits, -1);

                if (strcmp($rangeValue, $rangeStart) >= 0 && strcmp($rangeValue, $rangeEnd) <= 0) {
                    if ($length === 13) {
                        $rangeInfo->parts = [$isbnPrefix, $isbnGroup, $rangeValue, $lastDigits, $checkDigit];
                    } else {
                        $rangeInfo->parts = [$isbnGroup, $rangeValue, $lastDigits, $checkDigit];
                    }

                    break;
                }
            }

            return $rangeInfo;
        }

        return null;
    }
378563
public function get10()
    {
        // Is it valid?
        if ($this->isValid()) {
            // Is it already an ISBN-10?  If so, return as-is.
            if (strlen($this->raw) == 10) {
                return $this->raw;
            } elseif (strlen($this->raw) == 13
                && substr($this->raw, 0, 3) == '978'
            ) {
                // Is it a Bookland EAN?  If so, we can convert to ISBN-10.
                $start = substr($this->raw, 3, 9);
                return $start . self::getISBN10CheckDigit($start);
            }
        }

        // If we made it this far, conversion was not possible:
        return false;
    }
346686
function parseReadme(book) {
    var logger = book.getLogger();

    return parseStructureFile(book, 'readme')
    .spread(function(file, result) {
        if (!file) {
            throw new error.FileNotFoundError({ filename: 'README' });
        }

        logger.debug.ln('readme found at', file.getPath());

        var readme = Readme.create(file, result);
        return book.set('readme', readme);
    });
}
7896
static <T extends FunctionMeta> Map<T, IDataModel> toMetaFunctions(IDataModel book, Class<T> metaClass) {
        return toMetaFunctions(DataModelConverters.toWorkbook(book), metaClass);
    }
1104498
protected function fixBackMatterStructure( array $book_structure, $has_permission, array $replacement_keys ) {

		$base = 'back-matter';
		$rest_url = rest_url( sprintf( '%s/%s', $this->namespace, $base ) );

		$back_matter = [];
		foreach ( $book_structure['back-matter'] as $old_bm ) {
			if ( $has_permission || in_array( $old_bm['post_status'], [ 'web-only', 'publish' ], true ) ) {
				$new_bm = [];
				foreach ( $old_bm as $old_key => $val ) {
					$new_key = strtr( $old_key, $replacement_keys );
					$new_bm[ $new_key ] = $val;
				}
				$new_bm['link'] = get_permalink( $new_bm['id'] );
				$new_bm['back-matter-type'] = wp_get_object_terms(
					$new_bm['id'], 'back-matter-type', [
						'fields' => 'ids',
					]
				);
				$this->linkCollector['back-matter'][] = [
					'href' => trailingslashit( $rest_url ) . $new_bm['id'],
					'embeddable' => true,
				];

				// Metadata
				$request_metadata = new \WP_REST_Request( 'GET', "/pressbooks/v2/{$base}/{$new_bm['id']}/metadata" );
				$response_metadata = rest_do_request( $request_metadata );
				$new_bm['metadata'] = $this->prepare_response_for_collection( $response_metadata );
				$this->linkCollector['metadata'][] = [
					'href' => trailingslashit( $rest_url ) . "{$new_bm['id']}/metadata",
				];
				unset( $new_bm['metadata']['_links'] );

				$back_matter[] = $new_bm;
			}
		}

		return $back_matter;
	}