dseditor commited on
Commit
d867e16
·
verified ·
1 Parent(s): 40fe799

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -43,9 +43,9 @@ def format_docx(file, chapter_keywords):
43
  paragraph.style.paragraph_format.space_after = Cm(0)
44
  paragraph.style.paragraph_format.line_spacing = 1.0
45
 
46
- # 2. 縮排與行距位移兩公分
47
- paragraph.paragraph_format.left_indent = Cm(2)
48
- paragraph.paragraph_format.first_line_indent = Cm(0)
49
 
50
  # 3. 檢查是否為章節標題
51
  if re.search(combined_pattern, paragraph.text):
@@ -76,8 +76,9 @@ def format_docx(file, chapter_keywords):
76
  # 4. 在章節前分頁
77
  paragraph.paragraph_format.page_break_before = True
78
 
79
- # 重置章節標題的縮排
80
  paragraph.paragraph_format.left_indent = Cm(0)
 
81
 
82
  # 儲存處理後的文件
83
  output_path = tempfile.mktemp(suffix='.docx')
@@ -140,9 +141,9 @@ def create_interface():
140
  <h3>🛠️ 處理功能說明</h3>
141
  <ul>
142
  <li><strong>樣式調整:</strong>將所有段落設定為無間距樣式</li>
143
- <li><strong>縮排設定:</strong>所有段落左縮排 2 公分</li>
144
  <li><strong>章節識別:</strong>自動識別章節標題(如「第一章」、「第二節」等)</li>
145
- <li><strong>標題格式:</strong>章節標題設定為粗體標題 1 樣式</li>
146
  <li><strong>分頁設定:</strong>每個章節前自動分頁</li>
147
  </ul>
148
  </div>
 
43
  paragraph.style.paragraph_format.space_after = Cm(0)
44
  paragraph.style.paragraph_format.line_spacing = 1.0
45
 
46
+ # 2. 首行縮排兩個字元位置(約0.7公分)
47
+ paragraph.paragraph_format.left_indent = Cm(0) # 整體不縮排
48
+ paragraph.paragraph_format.first_line_indent = Cm(0.7) # 只有首行縮排
49
 
50
  # 3. 檢查是否為章節標題
51
  if re.search(combined_pattern, paragraph.text):
 
76
  # 4. 在章節前分頁
77
  paragraph.paragraph_format.page_break_before = True
78
 
79
+ # 重置章節標題的縮排(標題不需要首行縮排)
80
  paragraph.paragraph_format.left_indent = Cm(0)
81
+ paragraph.paragraph_format.first_line_indent = Cm(0)
82
 
83
  # 儲存處理後的文件
84
  output_path = tempfile.mktemp(suffix='.docx')
 
141
  <h3>🛠️ 處理功能說明</h3>
142
  <ul>
143
  <li><strong>樣式調整:</strong>將所有段落設定為無間距樣式</li>
144
+ <li><strong>首行縮排:</strong>每個段落首行縮排 2 個字元位置</li>
145
  <li><strong>章節識別:</strong>自動識別章節標題(如「第一章」、「第二節」等)</li>
146
+ <li><strong>標題格式:</strong>章節標題設定為粗體標題 1 樣式(無縮排)</li>
147
  <li><strong>分頁設定:</strong>每個章節前自動分頁</li>
148
  </ul>
149
  </div>