fix: improve line handling in VBA code extraction to avoid extra blank lines
This commit is contained in:
@@ -66,7 +66,10 @@ class VBAExtractor:
|
|||||||
(attributes_dict, clean_code) - 属性字典和清理后的代码
|
(attributes_dict, clean_code) - 属性字典和清理后的代码
|
||||||
"""
|
"""
|
||||||
attributes = {}
|
attributes = {}
|
||||||
lines = code.split('\n')
|
|
||||||
|
# [修复] 使用 splitlines() 自动处理 \r\n,避免保留 \r 导致的多余空行
|
||||||
|
lines = code.splitlines()
|
||||||
|
|
||||||
clean_lines = []
|
clean_lines = []
|
||||||
in_attributes = True
|
in_attributes = True
|
||||||
|
|
||||||
@@ -87,7 +90,8 @@ class VBAExtractor:
|
|||||||
# 添加到清理后的代码(跳过空行和Attribute)
|
# 添加到清理后的代码(跳过空行和Attribute)
|
||||||
if not in_attributes or (line.strip() and not line.strip().startswith('Attribute')):
|
if not in_attributes or (line.strip() and not line.strip().startswith('Attribute')):
|
||||||
if not in_attributes:
|
if not in_attributes:
|
||||||
clean_lines.append(line)
|
# 使用 rstrip() 去除行尾可能存在的空白符,保持代码整洁
|
||||||
|
clean_lines.append(line.rstrip())
|
||||||
|
|
||||||
# 去除开头的空行
|
# 去除开头的空行
|
||||||
while clean_lines and not clean_lines[0].strip():
|
while clean_lines and not clean_lines[0].strip():
|
||||||
|
|||||||
Reference in New Issue
Block a user