';
$in_list = false;
}
continue;
}
if ( preg_match( '/^######\s+(.*)/', $line, $m ) ) {
$html_lines[] = '
' . self::format_inline( $m[1] ) . '
';
} elseif ( preg_match( '/^#####\s+(.*)/', $line, $m ) ) {
$html_lines[] = '' . self::format_inline( $m[1] ) . '
';
} elseif ( preg_match( '/^####\s+(.*)/', $line, $m ) ) {
$html_lines[] = '' . self::format_inline( $m[1] ) . '
';
} elseif ( preg_match( '/^###\s+(.*)/', $line, $m ) ) {
$html_lines[] = '' . self::format_inline( $m[1] ) . '
';
} elseif ( preg_match( '/^##\s+(.*)/', $line, $m ) ) {
$html_lines[] = '' . self::format_inline( $m[1] ) . '
';
} elseif ( preg_match( '/^#\s+(.*)/', $line, $m ) ) {
$html_lines[] = '' . self::format_inline( $m[1] ) . '
';
} elseif ( preg_match( '/^[-*+]\s+(.*)/', $line, $m ) ) {
if ( ! $in_list ) {
$html_lines[] = '';
$in_list = true;
}
$html_lines[] = '- ' . self::format_inline( $m[1] ) . '
';
} else {
if ( $in_list ) {
$html_lines[] = '
';
$in_list = false;
}
$html_lines[] = '' . self::format_inline( $line ) . '
';
}
}
if ( $in_list ) {
$html_lines[] = '';
}
return implode( "\n", $html_lines );
}
/**
* Convert inline markdown elements.
*/
private static function format_inline( string $text ): string {
$text = preg_replace( '/\*\*(.+?)\*\*/s', '$1', $text );
$text = preg_replace( '/\*(.+?)\*/s', '$1', $text );
$text = preg_replace( '/\[(.+?)\]\((.+?)\)/s', '$1', $text );
return $text;
}
}