From 96cafb3ef2d86e2d157d79f67f873906a8318938 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 13:45:50 -0600 Subject: [PATCH] Warn if increasing headings goes past H6 Only warn once per entry. --- jrnl/plugins/markdown_exporter.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index 27bd44e1..9166a203 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -4,6 +4,8 @@ from __future__ import absolute_import, unicode_literals from .text_exporter import TextExporter import re +import sys +import colorama class MarkdownExporter(TextExporter): @@ -26,10 +28,13 @@ class MarkdownExporter(TextExporter): '''Increase heading levels in body text''' newbody = '' previous_line = '' + warn_on_heading_level = False for line in body.splitlines(True): if re.match(r"#+ ", line): """ATX style headings""" newbody = newbody + previous_line + heading + line + if re.match(r"#######+ ", heading + line): + warn_on_heading_level = True line = '' elif re.match(r"=+$", line) and not re.match(r"^$", previous_line): """Setext style H1""" @@ -42,7 +47,10 @@ class MarkdownExporter(TextExporter): else: newbody = newbody + previous_line previous_line = line - newbody = newbody + previous_line + newbody = newbody + previous_line # add very last line + + if warn_on_heading_level is True: + print("{}WARNING{}: Headings increased past H6 on export - {} {}".format(colorama.Fore.YELLOW, colorama.Style.RESET_ALL, date_str, entry.title), file=sys.stderr) return "{md} {date} {title} {body} {space}".format( md=heading,