From 4ebe4b853f80dd60a7b7d5ac61c516ead4d1993f Mon Sep 17 00:00:00 2001 From: Takayuki Miyoshi Date: Sun, 4 Dec 2022 17:11:15 +0900 Subject: [PATCH] Update html-formatter.php #1068 #525 --- includes/html-formatter.php | 40 +++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/includes/html-formatter.php b/includes/html-formatter.php index efafb2ff..6e1d70c1 100644 --- a/includes/html-formatter.php +++ b/includes/html-formatter.php @@ -1,10 +1,11 @@ options = wp_parse_args( $args, array( 'auto_br' => true, @@ -83,7 +88,15 @@ public function __construct( $args = '' ) { ) ); } - public function separate_into_chunks( string $input ) { + + /** + * Separates the given text into chunks of HTML. Each chunk must be an + * associative array that includes 'position', 'type', and 'content' keys. + * + * @param string $input Text to be separated into chunks. + * @return iterable Iterable of chunks. + */ + public function separate_into_chunks( $input ) { $input_bytelength = strlen( $input ); $position = 0; @@ -143,6 +156,14 @@ public function separate_into_chunks( string $input ) { } } + + /** + * Normalizes content in each chunk. This may change the type and position + * of the chunk. + * + * @param iterable $chunks The original chunks. + * @return iterable Normalized chunks. + */ public function pre_format( $chunks ) { $position = 0; @@ -173,6 +194,13 @@ public function pre_format( $chunks ) { } } + + /** + * Concatenates neighboring text chunks to create a single chunk. + * + * @param iterable $chunks The original chunks. + * @return iterable Processed chunks. + */ public function concatenate_texts( $chunks ) { $position = 0; $text_left = null;