Skip to content

Commit 4fcc61e

Browse files
author
p12
committed
Transform/DDG: trim the description at the first dot, not the last
1 parent 4007110 commit 4fcc61e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ddg_parse_html.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def process_description(el):
159159
last_open = -1
160160
last_close = -1
161161
open_count = 0
162-
last_dot = -1
162+
first_dot = -1
163163

164164
for t in re.finditer('<(/?(?:code|i|b))>', desc):
165165
if t.group(1)[0] != '/':
@@ -169,8 +169,8 @@ def process_description(el):
169169
# find any dots in the top level text
170170
if last_close != -1:
171171
pos = desc[last_close:last_open].rfind('.')
172-
if pos != -1:
173-
last_dot = last_close + pos
172+
if pos != -1 and first_dot == -1:
173+
first_dot = last_close + pos
174174
open_count += 1
175175

176176
else:
@@ -185,10 +185,10 @@ def process_description(el):
185185
last_close = 0
186186

187187
pos = desc[last_close:].rfind('.')
188-
if pos != -1:
189-
last_dot = last_close + pos
188+
if pos != -1 and first_dot == -1:
189+
first_dot = last_close + pos
190190

191-
if last_dot == -1 or last_dot > len(desc):
191+
if first_dot == -1 or first_dot > len(desc):
192192
iepos = desc.rfind('ᚃ')
193193
if iepos != -1 and iepos > 2:
194194
# string is too long but we can cut it at 'i.e.'
@@ -205,7 +205,7 @@ def process_description(el):
205205
else:
206206
desc = desc + '...'
207207
else:
208-
desc = desc[:last_dot] + '.'
208+
desc = desc[:first_dot] + '.'
209209
desc = desc.replace('ᚃ', 'i.e.')
210210
return desc
211211

0 commit comments

Comments
 (0)