Skip to content

Commit

Permalink
add list tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsnell committed Apr 4, 2024
1 parent 792651f commit 598fdd0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/wp-includes/html-api/class-wp-html-to-markdown-converter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
<?php

class WP_HTML_To_Markdown_Converter {
public static function list_tokens( $html ) {
$processor = WP_HTML_Processor::create_fragment( $html );
echo "\n";
$depth = 0;
while ( $processor->next_token() ) {
$depth += $processor->is_tag_closer() ? -1 : 1;

$closer = ( '#tag' === $processor->get_token_type() ) ? ( $processor->is_tag_closer() ? '-' : '+' ) : ' ';
$name = str_pad( "\e[36m{$closer}\e[32m{$processor->get_token_name()}", 14, ' ', STR_PAD_LEFT );

echo "{$name}\e[90m (\e[31m{$depth}\e[90m): {$processor->get_modifiable_text()}\e[m\n";
}
}
public static function normalize_html( $html ) {
$processor = WP_HTML_Processor::create_fragment( $html );
$output = '';
Expand Down Expand Up @@ -233,7 +246,8 @@ public static function convert( $html ) {
break;

case 'OL':
$lists[] = array( 'OL', 0 );
$start = intval( $processor->get_attribute( 'start' ) ?? '1' );
$lists[] = array( 'OL', $start - 1 );
break;

case 'UL':
Expand Down

0 comments on commit 598fdd0

Please sign in to comment.