';
$title = $structure_item['title'];
$style = $structure_item['style'];
$items = $structure_item['items'];
$ordered = false;
if ( $style === 'numbered' ) {
$ordered = true;
}
$toc_html .= '
' . $title . '
';
$toc_html .= $ordered ? '' : '
' : '';
$toc_html .= '';
return $toc_html;
}
/**
* Image for post.
*
* @param array $structure_item Image Structure data of post.
* @return string Image html.
*/
function sage_ai_make_image_for_classic_editor( $structure_item ) {
$url = $structure_item['text'];
$alt = $structure_item['alt'];
$image_html = '
';
return $image_html;
}
/**
* Article body of the post.
*
* @param array $structure_item article content structure data.
* @return string Article body HTML.
*/
function sage_ai_make_paragraphs_for_classic_editor( $structure_item ) {
$html_content = '';
if ( ! empty( $structure_item['headingTag'] ) ) {
$heading_tag = $structure_item['headingTag'];
$heading_text = $structure_item['headingText'];
$id = preg_replace( '/\W/', '-', $heading_text );
$id = preg_replace( '/^\d+\s*/', '', $id ); // replace starting number if any
$id = strtolower( $id );
$heading_level = 2;
switch ( $heading_tag ) {
case 'h1':
$html_content .= '' . $heading_text . '
';
break;
case 'h2':
$html_content .= '' . $heading_text . '
';
break;
case 'h3':
$html_content .= '' . $heading_text . '
';
break;
case 'h4':
$html_content .= '' . $heading_text . '
';
break;
case 'h5':
$html_content .= '' . $heading_text . '
';
break;
case 'h6':
$html_content .= '' . $heading_text . '
';
break;
}
}
$paragraph = $structure_item['text'];
// look for list items (step 1: or 1.)
$list_items = preg_replace( '/(step\s\d+:|\d+\.)\s/i', '', $paragraph );
$first_list_item_pos = strpos( $list_items, '' );
if ( $first_list_item_pos !== false ) {
// text contains list items
$text_items = explode( '', $list_items );
$text = '';
if ( isset( $text_items[0] ) ) {
// some intro paragraph before list begins
$text .= '' . $text_items[0] . '
';
array_shift( $text_items ); // remove first para from textitems for further processing
}
$text .= '';
foreach ( $text_items as $item ) {
$text .= '- ' . $item . '
';
}
$text .= '
';
$html_content .= $text;
} else {
$html_content .= '' . $paragraph . '
';
}
return $html_content;
}