{% macro wrap_model_string(doc_string, wrap_string, suffix_string="") %}
{# Check if this is a sphinx documentation line that should not have extra prefix spacing #}
{%- set is_sphinx_doc = doc_string.strip().startswith(':ivar') or doc_string.strip().startswith(':vartype') or doc_string.strip().startswith(':param') or doc_string.strip().startswith(':type') -%}
{# Custom handling for bullet points - normalization is now done in preprocessing #}
{% set enable_custom_handling = "\n* " in doc_string or doc_string.startswith("* ") %}
{# Normalize multi-line descriptions by collapsing internal new_lines to spaces, but preserve special blocks #}
{%- if not enable_custom_handling -%}
    {%- if '.. code-block::' in doc_string -%}
        {# Split at code block and only normalize the prose before it #}
        {%- set parts = doc_string.split('.. code-block::') -%}
        {%- set prose = parts[0].rstrip() -%}
        {%- set code_block = '.. code-block::' + parts[1:] | join('.. code-block::') -%}
        {%- if '\n\n' not in prose -%}
            {%- set normalized_lines = [] -%}
            {%- for line in prose.split('\n') -%}
                {%- set stripped = line.strip() -%}
                {%- if stripped -%}
                    {%- set _ = normalized_lines.append(stripped) -%}
                {%- endif -%}
            {%- endfor -%}
            {%- set doc_string = normalized_lines | join(' ') + '\n\n' + code_block -%}
        {%- endif -%}
    {%- elif '\n\n' not in doc_string -%}
        {%- set normalized_lines = [] -%}
        {%- for line in doc_string.split('\n') -%}
            {%- set stripped = line.strip() -%}
            {%- if stripped -%}
                {%- set _ = normalized_lines.append(stripped) -%}
            {%- endif -%}
        {%- endfor -%}
        {%- set doc_string = normalized_lines | join(' ') -%}
    {%- endif -%}
{%- endif -%}
{%- if enable_custom_handling -%}
    {# First, normalize prose before bullet points by splitting at first bullet #}
    {%- set normalized_doc = doc_string -%}
    {%- if '\n* ' in doc_string -%}
        {%- set parts = doc_string.split('\n* ', 1) -%}
        {%- set prose_part = parts[0] -%}
        {%- set bullet_part = '* ' + parts[1] -%}
        {# Normalize the prose part #}
        {%- set prose_lines = [] -%}
        {%- for line in prose_part.split('\n') -%}
            {%- set stripped = line.strip() -%}
            {%- if stripped -%}
                {%- set _ = prose_lines.append(stripped) -%}
            {%- endif -%}
        {%- endfor -%}
        {%- set normalized_doc = prose_lines | join(' ') + '\n\n' + bullet_part -%}
    {%- endif -%}
    {%- set lines = normalized_doc.split('\n') -%}
    {%- set base_indent = wrap_string.lstrip('\n') -%}
    {%- set result_lines = [] -%}
    {%- for line in lines -%}
        {%- if line.strip().startswith('* ') -%}
            {# Handle bullet points with proper continuation alignment #}
            {%- set bullet_content = line.strip()[2:] -%}
            {%- set bullet_line = base_indent + ' * ' + bullet_content -%}
            {%- set continuation_spaces = base_indent + '   ' -%}
            {%- set wrapped = bullet_line | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n' + continuation_spaces) -%}
            {%- set _ = result_lines.append(wrapped) -%}
        {%- elif line.strip() -%}
            {%- set stripped_line = line.strip() -%}
            {%- set line_indent = '' if stripped_line.startswith(':') or loop.index == 1 else (base_indent + ' ') -%}
            {%- set wrapped = (line_indent + stripped_line) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring=wrap_string) -%}
            {%- for w_line in wrapped.split('\n') -%}
                {%- set prefix = "" if loop.index == 1 else " " -%}
                {%- set _ = result_lines.append(prefix + w_line) -%}
            {%- endfor -%}
        {%- else -%}
            {# Do not add continuous blank lines #}
            {%- if (result_lines and result_lines[-1] != '') or not result_lines -%}
              {%- set _ = result_lines.append('') -%}
            {%- endif -%}
        {%- endif -%}
    {%- endfor -%}
    {%- set original_result = result_lines | join('\n') -%}
{%- else -%}
    {# Regular text handling #}
    {%- set original_result = doc_string | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring=wrap_string) -%}
{%- endif -%}
{% set list_result = original_result.split('\n') %}
{% for line in list_result %}
    {%- if is_sphinx_doc and enable_custom_handling -%}
        {%- set prefix = "" -%}
    {%- else -%}
        {%- set prefix = "" if loop.index == 1 else " " -%}
    {%- endif -%}
    {% set suffix = suffix_string if list_result | length == loop.index %}
{{ prefix }}{{ line }}{{ suffix }}
{% endfor %}
{% endmacro %}
