@@ -390,16 +390,27 @@ def _convert_input(source, format, input_type, to, extra_args=(),
390
390
391
391
392
392
def _classify_pandoc_logging (raw , default_level = "WARNING" ):
393
- # Process raw and yeild the contained logging levels and messages.
393
+ # Process raw and yield the contained logging levels and messages.
394
394
# Assumes that the messages are formatted like "[LEVEL] message". If the
395
- # first message does not have a level, use the default_level value instead.
395
+ # first message does not have a level or any other message has a level
396
+ # that does not conform to the pandoc standard, use the default_level
397
+ # value instead.
396
398
397
- level_map = {"CRITICAL" : 50 ,
398
- "ERROR" : 40 ,
399
- "WARNING" : 30 ,
400
- "INFO" : 20 ,
401
- "DEBUG" : 10 ,
402
- "NOTSET" : 0 }
399
+ # Available pandoc logging levels adapted from:
400
+ # https://github.com/jgm/pandoc/blob/5e1249481b2e3fc27e845245a0c96c3687a23c3d/src/Text/Pandoc/Logging.hs#L44
401
+ def get_python_level (pandoc_level ):
402
+
403
+ level_map = {"ERROR" : 40 ,
404
+ "WARNING" : 30 ,
405
+ "INFO" : 20 ,
406
+ "DEBUG" : 10 }
407
+
408
+ if pandoc_level not in level_map :
409
+ level = level_map [default_level ]
410
+ else :
411
+ level = level_map [pandoc_level ]
412
+
413
+ return level
403
414
404
415
msgs = raw .split ("\n " )
405
416
first = msgs .pop (0 )
@@ -408,29 +419,25 @@ def _classify_pandoc_logging(raw, default_level="WARNING"):
408
419
409
420
# Use the default if the first message doesn't have a level
410
421
if search is None :
411
- level = default_level
422
+ pandoc_level = default_level
412
423
else :
413
- level = first [search .start (1 ):search .end (1 )]
414
-
415
- log_msgs = [first .replace ('[{}] ' .format (level ), '' )]
416
-
417
- if level not in level_map :
418
- level = default_level
424
+ pandoc_level = first [search .start (1 ):search .end (1 )]
419
425
426
+ log_msgs = [first .replace ('[{}] ' .format (pandoc_level ), '' )]
420
427
421
428
for msg in msgs :
422
429
423
430
search = re .search (r"\[(.*?)\]" , msg )
424
431
425
432
if search is not None :
426
- yield level_map [ level ] , "\n " .join (log_msgs )
427
- level = msg [search .start (1 ):search .end (1 )]
428
- log_msgs = [msg .replace ('[{}] ' .format (level ), '' )]
433
+ yield get_python_level ( pandoc_level ) , "\n " .join (log_msgs )
434
+ pandoc_level = msg [search .start (1 ):search .end (1 )]
435
+ log_msgs = [msg .replace ('[{}] ' .format (pandoc_level ), '' )]
429
436
continue
430
437
431
438
log_msgs .append (msg )
432
439
433
- yield level_map [ level ] , "\n " .join (log_msgs )
440
+ yield get_python_level ( pandoc_level ) , "\n " .join (log_msgs )
434
441
435
442
436
443
def _get_base_format (format ):
0 commit comments