diff --git a/tools.py b/tools.py index 14b9d62..dc5b265 100644 --- a/tools.py +++ b/tools.py @@ -89,16 +89,12 @@ class MarkdownWithMath(mistune.Markdown): class HighlightRenderer(mistune.Renderer): def block_code(self, code, lang='text'): try: - lexer = get_lexer_by_name(lang, stripall=True) + lexer = get_lexer_by_name(lang, stripall=False) except: - lexer = get_lexer_by_name('text', stripall=True) + lexer = get_lexer_by_name('text', stripall=False) formatter = HtmlFormatter() - return "{open_block}{formatted}{close_block}".format( - open_block="
" if lang != 'text' else '', - formatted=highlight(code, lexer, formatter), - close_block="
" if lang != 'text' else '' - ) + return highlight(code, lexer, formatter) # def table(self, header, body): # return "" + header + body + "
" @@ -148,7 +144,7 @@ def load_yaml(filename, default=None): return yaml.load(f) except yaml.YAMLError as e: mark = e.problem_mark - logger.error('In YAML file "{0}" near line {1}, column {2}.'.format(filename, mark.line, mark.column+1)) + logger.error(f'In YAML file "{filename}" near line {mark.line}, column {mark.column+1}.') return default # --------------------------------------------------------------------------- @@ -165,11 +161,13 @@ def run_script(script, stdin='', timeout=5): timeout=timeout, ) except FileNotFoundError: - logger.error(f'Script "{script}" not found.') + logger.error(f'Could not execute script "{script}": not found.') except PermissionError: - logger.error(f'Script "{script}" not executable. Wrong permissions?') + logger.error(f'Could not execute script "{script}": wrong permissions.') + except OSError: + logger.error(f'Could not execute script "{script}": unknown reason.') except subprocess.TimeoutExpired: - logger.error(f'Timeout {timeout}s exceeded while running "{script}".') + logger.error(f'Timeout exceeded ({timeout}s) while running "{script}".') else: if p.returncode != 0: logger.error(f'Script "{script}" returned error code {p.returncode}.') @@ -177,6 +175,6 @@ def run_script(script, stdin='', timeout=5): try: output = yaml.load(p.stdout) except: - logger.error('Error parsing yaml output of "{script}"') + logger.error(f'Error parsing yaml output of "{script}"') else: return output -- libgit2 0.21.2