@@ -188,7 +188,7 @@ def link(external=False):
188
188
bwrite ("[http://news.ycombinator.com/item?id=%s]" % item_id )
189
189
if 'content' in item :
190
190
bwrite ("" )
191
- print_content ( item ['content' ])
191
+ print_comments ([ dict ( content = item ['content' ]) ])
192
192
if 'poll' in item :
193
193
bwrite ("" )
194
194
max_score = max ((c ['points' ] for c in item ['poll' ]))
@@ -249,45 +249,13 @@ def recall_pos():
249
249
vim .current .window .cursor = (int (mark [0 ]), int (mark [1 ]))
250
250
251
251
252
- def print_content (content ):
253
- for p in content .split ("<p>" ):
254
- if not p :
255
- continue
256
- p = html .unescape (p )
257
- p = p .replace ("<i>" , "_" ).replace ("</i>" , "_" )
258
-
259
- # Convert <a href="http://url/">Text</a> tags
260
- # to markdown equivalent: (Text)[http://url/]
261
- s = p .find ("a>" )
262
- while s > 0 :
263
- s += 2
264
- section = p [:s ]
265
- m = re .search (r"<a.*href=[\"\']([^\"\']*)[\"\'].*>(.*)</a>" ,
266
- section )
267
- if m :
268
- # Do not bother with anchor text if it is same as href url
269
- if m .group (1 )[:20 ] == m .group (2 )[:20 ]:
270
- p = p .replace (m .group (0 ), "[%s]" % m .group (1 ))
271
- else :
272
- p = p .replace (m .group (0 ),
273
- "(%s)[%s]" % (m .group (2 ), m .group (1 )))
274
- s = p .find ("a>" )
275
- else :
276
- s = p .find ("a>" , s )
277
-
278
- contents = textwrap .wrap (p , width = 80 )
279
- for line in contents :
280
- if line .strip ():
281
- bwrite (line )
282
- if contents and line .strip ():
283
- bwrite ("" )
284
-
285
-
286
252
def print_comments (comments , level = 0 ):
287
253
for comment in comments :
288
- bwrite ("%sComment by %s %s:"
289
- % (" " * level * 4 , comment .get ('user' , '???' ),
290
- comment ['time_ago' ]))
254
+ if 'level' in comment :
255
+ # This is a comment (not content) so add comment header
256
+ bwrite ("%sComment by %s %s:"
257
+ % (" " * level * 4 , comment .get ('user' , '???' ),
258
+ comment ['time_ago' ]))
291
259
for p in comment ['content' ].split ("<p>" ):
292
260
if not p :
293
261
continue
@@ -336,4 +304,5 @@ def print_comments(comments, level=0):
336
304
if contents and line .strip ():
337
305
bwrite ("" )
338
306
bwrite ("" )
339
- print_comments (comment ['comments' ], level + 1 )
307
+ if 'comments' in comment :
308
+ print_comments (comment ['comments' ], level + 1 )
0 commit comments