From fafcd23e08f193dcb8b1eae6b8fde80114909fad Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Mon, 13 Nov 2017 18:04:24 -0700 Subject: [PATCH 1/3] Switch to hashmark Markdown headers on export Closes #487 --- jrnl/plugins/markdown_exporter.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index 147e8ac5..0a237af4 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -68,12 +68,10 @@ class MarkdownExporter(TextExporter): for e in journal.entries: if not e.date.year == year: year = e.date.year - out.append(str(year)) - out.append("=" * len(str(year)) + "\n") + out.append("# " + str(year)) if not e.date.month == month: month = e.date.month - out.append(e.date.strftime("%B")) - out.append('-' * len(e.date.strftime("%B")) + "\n") + out.append("## " + e.date.strftime("%B")) out.append(cls.export_entry(e, False)) result = "\n".join(out) return result From a9499eec62397b91105d19e2e3401e0f3c60f875 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Thu, 1 Aug 2019 21:00:53 -0600 Subject: [PATCH 2/3] [Markdown Export] deal with linebreaks in jrnl files --- features/exporting.feature | 6 ++---- jrnl/plugins/markdown_exporter.py | 11 +++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/features/exporting.feature b/features/exporting.feature index 1b4285ed..db2ef5b3 100644 --- a/features/exporting.feature +++ b/features/exporting.feature @@ -42,11 +42,9 @@ Feature: Exporting a Journal When we run "jrnl --export markdown" Then the output should be """ - 2015 - ==== + # 2015 - April - ----- + ## April ### 2015-04-14 13:23 Heading Test diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index 0a237af4..19b5404d 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals, print_function from .text_exporter import TextExporter +import os import re import sys from ..util import WARNING_COLOR, RESET_COLOR @@ -30,17 +31,17 @@ class MarkdownExporter(TextExporter): previous_line = '' warn_on_heading_level = False for line in body.splitlines(True): - if re.match(r"#+ ", line): + if re.match(r"^#+ ", line): """ATX style headings""" newbody = newbody + previous_line + heading + line - if re.match(r"#######+ ", 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): + elif re.match(r"^=+$", line.rstrip()) and not re.match(r"^$", previous_line.strip()): """Setext style H1""" newbody = newbody + heading + "# " + previous_line line = '' - elif re.match(r"-+$", line) and not re.match(r"^$", previous_line): + elif re.match(r"^-+$", line.rstrip()) and not re.match(r"^$", previous_line.strip()): """Setext style H2""" newbody = newbody + heading + "## " + previous_line line = '' @@ -69,9 +70,11 @@ class MarkdownExporter(TextExporter): if not e.date.year == year: year = e.date.year out.append("# " + str(year)) + out.append("") if not e.date.month == month: month = e.date.month out.append("## " + e.date.strftime("%B")) + out.append("") out.append(cls.export_entry(e, False)) result = "\n".join(out) return result From 9299eb36e640349a036f2516696844242c0ec11e Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Thu, 1 Aug 2019 21:21:55 -0600 Subject: [PATCH 3/3] [YAML Exporter] apply fix just applied to Markdown Exporter --- jrnl/plugins/yaml_exporter.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py index 1442adcc..c0735811 100644 --- a/jrnl/plugins/yaml_exporter.py +++ b/jrnl/plugins/yaml_exporter.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals, print_function from .text_exporter import TextExporter +import os import re import sys from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR @@ -34,17 +35,17 @@ class YAMLExporter(TextExporter): previous_line = '' warn_on_heading_level = False for line in entry.body.splitlines(True): - if re.match(r"#+ ", line): + if re.match(r"^#+ ", line): """ATX style headings""" newbody = newbody + previous_line + heading + line - if re.match(r"#######+ ", 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): + elif re.match(r"^=+$", line.rstrip()) and not re.match(r"^$", previous_line.strip()): """Setext style H1""" newbody = newbody + heading + "# " + previous_line line = '' - elif re.match(r"-+$", line) and not re.match(r"^$", previous_line): + elif re.match(r"^-+$", line.rstrip()) and not re.match(r"^$", previous_line.strip()): """Setext style H2""" newbody = newbody + heading + "## " + previous_line line = ''