Skip to content

Commit

Permalink
解决数字超过9后的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Higurashi-kagome committed May 27, 2020
1 parent 7c77bfd commit ccfbfbd
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions AddTitleNumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ def add_number_for_line(line_which_is_title,title_sign):
titles_added_number.append(line_which_is_title.replace(title_sign + ' ',title_sign + ' ' + number + '.1 '))
return titles_added_number[-1]
elif len(title_sign_list[-1]) == len(title_sign_list[-2]):#如果line_which_is_title与上一个标题等级别
titles_added_number.append(line_which_is_title.replace(title_sign + ' ',title_sign + ' ' + number[:-1] + str(int(number.split('.')[-1]) + 1) + ' '))
number_list = number.split('.')
number_suf = number_list.pop(-1)
number_pre = ''
for num in number_list:
number_pre += num + '.'
titles_added_number.append(line_which_is_title.replace(title_sign + ' ',title_sign + ' ' + number_pre + str(int(number_suf) + 1) + ' '))
return titles_added_number[-1]
elif len(title_sign_list[-1]) < len(title_sign_list[-2]):#如果line_which_is_title的上一个标题比它更低
for title in titles_added_number[::-1]:
Expand All @@ -69,7 +74,12 @@ def add_number_for_line(line_which_is_title,title_sign):
print('接收到y/n以外的输入,默认退出')
os._exit(0)
if len(sign) == len(title_sign):#如果找到等级别标题
titles_added_number.append(line_which_is_title.replace(title_sign + ' ',title_sign + ' ' + number[:-1] + str(int(number.split('.')[-1]) + 1) + ' '))
number_list = number.split('.')
number_suf = number_list.pop(-1)
number_pre = ''
for num in number_list:
number_pre += num + '.'
titles_added_number.append(line_which_is_title.replace(title_sign + ' ',title_sign + ' ' + number_pre + str(int(number_suf) + 1) + ' '))
return titles_added_number[-1]


Expand Down Expand Up @@ -102,9 +112,9 @@ def create_markdown_file_with_number(f):
print('请传入文件名')
os._exit(0)
file_name = sys.argv[1]
try:
if os.path.exists(file_name):
with open(file_name,'r',encoding='utf-8') as f:
create_markdown_file_with_number(f)
except:
else:
msg = "未找到文件"
print(msg)

0 comments on commit ccfbfbd

Please sign in to comment.