@@ -390,16 +390,27 @@ def _convert_input(source, format, input_type, to, extra_args=(),
390390
391391
392392def _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.
394394 # 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.
396398
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
403414
404415 msgs = raw .split ("\n " )
405416 first = msgs .pop (0 )
@@ -408,29 +419,25 @@ def _classify_pandoc_logging(raw, default_level="WARNING"):
408419
409420 # Use the default if the first message doesn't have a level
410421 if search is None :
411- level = default_level
422+ pandoc_level = default_level
412423 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 )]
419425
426+ log_msgs = [first .replace ('[{}] ' .format (pandoc_level ), '' )]
420427
421428 for msg in msgs :
422429
423430 search = re .search (r"\[(.*?)\]" , msg )
424431
425432 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 ), '' )]
429436 continue
430437
431438 log_msgs .append (msg )
432439
433- yield level_map [ level ] , "\n " .join (log_msgs )
440+ yield get_python_level ( pandoc_level ) , "\n " .join (log_msgs )
434441
435442
436443def _get_base_format (format ):
0 commit comments