X-Git-Url: https://git.madduck.net/etc/mutt.git/blobdiff_plain/7013dfe93a05082153f79eca6c9e5c05b54d9d50..6d900601163e87f851fa17a2859f9370be1df3e3:/.config/mutt/markdown2html diff --git a/.config/mutt/markdown2html b/.config/mutt/markdown2html index 309c22e..808ba2c 100755 --- a/.config/mutt/markdown2html +++ b/.config/mutt/markdown2html @@ -111,7 +111,7 @@ def _preprocess_signature(sig): ''' Preprocess the signature before markdown processing. ''' - return sig + return f"```\n{sig}\n```" def _preprocess_markdown(mdwn): ''' @@ -135,8 +135,7 @@ def _preprocess_markdown(mdwn): # when used around email addresses. Note that this needs a postprocessing # hack because the pandoc autolink converted includes the ambersand # (https://github.com/jgm/pandoc/issues/7398). - ret = re.sub(r'<([^@]+@.+\.[^>]+)>', r'<\g<1> -PANDOC_BUG_7398->', ret) - + ret = re.sub(r'<([^@]+@\S+)>', r'<\g<1> PANDOC_BUG_7398 >', ret) return ret @@ -218,7 +217,7 @@ def _reformat_quotes(html): def _convert_with_pandoc(mdwn, inputfmt='markdown', outputfmt='html5', ext_enabled=None, ext_disabled=None, - standalone=True, selfcontained=True, title=None): + standalone=True, selfcontained=True, title='Untitled'): ''' Invoke pandoc to do the actual conversion of Markdown to HTML5. ''' @@ -264,7 +263,7 @@ def _convert_with_pandoc(mdwn, inputfmt='markdown', outputfmt='html5', if selfcontained: args.append('--self-contained') if title: - args.append(f'--metadata=pagetitle:"{title}"') + args.append(f'--metadata=title:{title}') return pypandoc.convert_text(mdwn, format=inputfmt, to=outputfmt, extra_args=args) @@ -284,7 +283,7 @@ def _postprocess_html(html): # Preprocessing leaves a sentinel to work around # https://github.com/jgm/pandoc/issues/7398, and so we need to remove it: - html = html.replace(' -PANDOC_BUG_7398->', '>') + html = html.replace(' PANDOC_BUG_7398 ', '') return html @@ -293,7 +292,7 @@ def convert_markdown_to_html(mdwn): Converts the input Markdown to HTML, handling separately the body, as well as an optional signature. ''' - parts = re.split(r'^-- $', mdwn, 1, flags=re.MULTILINE) + parts = re.split(r'^-- \n', mdwn, 1, flags=re.MULTILINE) body = parts[0] if len(parts) == 2: sig = parts[1] @@ -305,15 +304,16 @@ def convert_markdown_to_html(mdwn): body = _preprocess_markdown(body) body = _identify_quotes_for_later(body) html = _convert_with_pandoc(body, standalone=True, selfcontained=True, - title=None) - html = html.replace('