diff --git a/.chronus/changes/python-addBullet-2025-9-16-16-11-41.md b/.chronus/changes/python-addBullet-2025-9-16-16-11-41.md new file mode 100644 index 00000000000..b8ef587d651 --- /dev/null +++ b/.chronus/changes/python-addBullet-2025-9-16-16-11-41.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Additional fixes to documentation with bullet points \ No newline at end of file diff --git a/packages/http-client-python/generator/pygen/codegen/templates/macros.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/macros.jinja2 index 8370863ceb1..1cc18a904ef 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/macros.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/macros.jinja2 @@ -1,8 +1,39 @@ {% macro wrap_model_string(doc_string, wrap_string, suffix_string="") %} -{% set original_result = doc_string | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring=wrap_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 = "* " in doc_string %} +{%- if enable_custom_handling -%} + {%- set lines = doc_string.split('\n') -%} + {%- set result_lines = [] -%} + {%- for line in lines -%} + {%- if line.startswith('* ') -%} + {# Handle bullet points with proper continuation alignment #} + {%- set bullet_content = line[2:] -%} + {%- set base_indent = wrap_string.lstrip('\n') -%} + {%- 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 wrapped = line.strip() | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring=wrap_string) -%} + {%- set _ = result_lines.append(wrapped) -%} + {%- else -%} + {%- set _ = result_lines.append('') -%} + {%- 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 %} - {% set prefix = "" if loop.index == 1 else " " %} + {%- 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 %}