feat: consolidate docs, backend/session infra, and settings updates

This commit is contained in:
Dwindi Ramadhana
2026-05-28 00:58:20 +07:00
parent 2424acf726
commit 44e06eed88
102 changed files with 35423 additions and 11181 deletions

View File

@@ -35,6 +35,7 @@ class WP_Agentic_Writer_Markdown_Parser {
$in_list = false;
$list_items = array();
$list_type = 'ul'; // 'ul' or 'ol'
$list_start = null;
$code_lines = array();
$code_language = '';
$in_auto_code_block = false;
@@ -89,9 +90,10 @@ class WP_Agentic_Writer_Markdown_Parser {
}
// Flush any pending list.
if ( $in_list ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
$list_items = array();
$in_list = false;
$list_start = null;
}
// Get agent_image_id from placeholders array if available
@@ -115,9 +117,10 @@ class WP_Agentic_Writer_Markdown_Parser {
}
// Flush any pending list.
if ( $in_list ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
$list_items = array();
$in_list = false;
$list_start = null;
}
// Create button block.
@@ -134,9 +137,10 @@ class WP_Agentic_Writer_Markdown_Parser {
}
// Flush any pending list.
if ( $in_list ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
$list_items = array();
$in_list = false;
$list_start = null;
}
$auto_code_language = preg_match( '/^(<\\?php|define\\s*\\(|\\$[A-Za-z_])/', $trimmed ) ? 'php' : 'text';
@@ -162,9 +166,10 @@ class WP_Agentic_Writer_Markdown_Parser {
}
// Flush any pending list.
if ( $in_list ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
$list_items = array();
$in_list = false;
$list_start = null;
}
$in_code_block = true;
$code_language = $matches[1];
@@ -186,9 +191,10 @@ class WP_Agentic_Writer_Markdown_Parser {
}
// Flush any pending list.
if ( $in_list ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
$list_items = array();
$in_list = false;
$list_start = null;
}
$level = strlen( $matches[1] );
@@ -206,9 +212,10 @@ class WP_Agentic_Writer_Markdown_Parser {
$current_paragraph = '';
}
if ( $in_list ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
$list_items = array();
$in_list = false;
$list_start = null;
}
$headers = self::split_table_row( $trimmed );
@@ -235,9 +242,10 @@ class WP_Agentic_Writer_Markdown_Parser {
$current_paragraph = '';
}
if ( $in_list ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
$list_items = array();
$in_list = false;
$list_start = null;
}
// Gutenberg doesn't have a native separator block, use a spacer.
$blocks[] = array(
@@ -258,11 +266,14 @@ class WP_Agentic_Writer_Markdown_Parser {
$current_paragraph = '';
}
if ( $in_list && $list_type !== 'ul' ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
$list_items = array();
$in_list = false;
$list_start = null;
}
$in_list = true;
$list_type = 'ul';
$list_start = null;
$list_items[] = self::parse_inline_markdown( $matches[1] );
continue;
}
@@ -274,9 +285,10 @@ class WP_Agentic_Writer_Markdown_Parser {
$current_paragraph = '';
}
if ( $in_list ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
$list_items = array();
$in_list = false;
$list_start = null;
}
// Create paragraph with manual numbering and bold title.
$content = $matches[1] . '. <strong>' . self::parse_inline_markdown( $matches[2] ) . '</strong>';
@@ -285,18 +297,23 @@ class WP_Agentic_Writer_Markdown_Parser {
}
// Handle ordered lists.
if ( preg_match( '/^\d+\.\s+(.+)$/', $trimmed, $matches ) ) {
if ( preg_match( '/^(\d+)\.\s+(.+)$/', $trimmed, $matches ) ) {
if ( ! empty( $current_paragraph ) ) {
$blocks[] = self::create_paragraph_block( $current_paragraph );
$current_paragraph = '';
}
if ( $in_list && $list_type !== 'ol' ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
$list_items = array();
$in_list = false;
$list_start = null;
}
if ( ! $in_list ) {
$list_start = (int) $matches[1];
}
$in_list = true;
$list_type = 'ol';
$list_items[] = self::parse_inline_markdown( $matches[1] );
$list_items[] = self::parse_inline_markdown( $matches[2] );
continue;
}
@@ -307,9 +324,10 @@ class WP_Agentic_Writer_Markdown_Parser {
$current_paragraph = '';
}
if ( $in_list ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
$list_items = array();
$in_list = false;
$list_start = null;
}
$blocks[] = self::create_quote_block( $matches[1] );
continue;
@@ -324,9 +342,10 @@ class WP_Agentic_Writer_Markdown_Parser {
}
// Flush list.
if ( $in_list ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
$list_items = array();
$in_list = false;
$list_start = null;
}
continue;
}
@@ -354,7 +373,7 @@ class WP_Agentic_Writer_Markdown_Parser {
$blocks[] = self::create_paragraph_block( $current_paragraph );
}
if ( $in_list ) {
$blocks[] = self::create_list_block( $list_type, $list_items );
$blocks[] = self::create_list_block( $list_type, $list_items, $list_start );
}
// Merge consecutive ordered lists (fix 1. 1. 1. issue)
@@ -597,11 +616,15 @@ class WP_Agentic_Writer_Markdown_Parser {
* @since 0.1.0
* @param string $type List type ('ul' or 'ol').
* @param array $items List items.
* @param int|null $start Ordered list start value.
* @return array Gutenberg block.
*/
private static function create_list_block( $type, $items ) {
private static function create_list_block( $type, $items, $start = null ) {
$tag = $type === 'ol' ? 'ol' : 'ul';
$html = '<' . $tag . '>';
$is_ordered = 'ol' === $tag;
$start = $is_ordered ? max( 1, (int) $start ) : null;
$start_attr = $is_ordered && $start > 1 ? ' start="' . $start . '"' : '';
$html = '<' . $tag . $start_attr . '>';
// Create inner blocks for each list item
$inner_blocks = array();
@@ -627,11 +650,17 @@ class WP_Agentic_Writer_Markdown_Parser {
$html .= '</' . $tag . '>';
$attrs = array(
'ordered' => $is_ordered,
);
if ( $is_ordered && $start > 1 ) {
$attrs['start'] = $start;
}
return array(
'blockName' => 'core/list',
'attrs' => array(
'ordered' => $type === 'ol',
),
'attrs' => $attrs,
'innerBlocks' => $inner_blocks,
'innerContent' => $inner_content,
'innerHTML' => $html,
@@ -735,7 +764,8 @@ class WP_Agentic_Writer_Markdown_Parser {
} else {
// Flush pending ordered list if we have one
if ( null !== $pending_ol && ! empty( $pending_ol_items ) ) {
$result[] = self::rebuild_ordered_list( $pending_ol_items );
$start = isset( $pending_ol['attrs']['start'] ) ? (int) $pending_ol['attrs']['start'] : 1;
$result[] = self::rebuild_ordered_list( $pending_ol_items, $start );
$pending_ol = null;
$pending_ol_items = array();
}
@@ -745,7 +775,8 @@ class WP_Agentic_Writer_Markdown_Parser {
// Flush any remaining ordered list
if ( null !== $pending_ol && ! empty( $pending_ol_items ) ) {
$result[] = self::rebuild_ordered_list( $pending_ol_items );
$start = isset( $pending_ol['attrs']['start'] ) ? (int) $pending_ol['attrs']['start'] : 1;
$result[] = self::rebuild_ordered_list( $pending_ol_items, $start );
}
return $result;
@@ -756,10 +787,13 @@ class WP_Agentic_Writer_Markdown_Parser {
*
* @since 0.1.0
* @param array $items List item blocks.
* @param int $start Ordered list start value.
* @return array Ordered list block.
*/
private static function rebuild_ordered_list( $items ) {
$html = '<ol>';
private static function rebuild_ordered_list( $items, $start = 1 ) {
$start = max( 1, (int) $start );
$start_attr = $start > 1 ? ' start="' . $start . '"' : '';
$html = '<ol' . $start_attr . '>';
$inner_content = array();
foreach ( $items as $item ) {
@@ -770,11 +804,17 @@ class WP_Agentic_Writer_Markdown_Parser {
$html .= '</ol>';
$attrs = array(
'ordered' => true,
);
if ( $start > 1 ) {
$attrs['start'] = $start;
}
return array(
'blockName' => 'core/list',
'attrs' => array(
'ordered' => true,
),
'attrs' => $attrs,
'innerBlocks' => $items,
'innerContent' => $inner_content,
'innerHTML' => $html,