[Markdown Export] deal with linebreaks in jrnl files

This commit is contained in:
MinchinWeb 2019-08-01 21:00:53 -06:00
parent 4513609954
commit 1884a6ce23
2 changed files with 9 additions and 8 deletions

View file

@ -42,11 +42,9 @@ Feature: Exporting a Journal
When we run "jrnl --export markdown" When we run "jrnl --export markdown"
Then the output should be Then the output should be
""" """
2015 # 2015
====
April ## April
-----
### 2015-04-14 13:23 Heading Test ### 2015-04-14 13:23 Heading Test

View file

@ -3,6 +3,7 @@
from __future__ import absolute_import, unicode_literals, print_function from __future__ import absolute_import, unicode_literals, print_function
from .text_exporter import TextExporter from .text_exporter import TextExporter
import os
import re import re
import sys import sys
from ..util import WARNING_COLOR, RESET_COLOR from ..util import WARNING_COLOR, RESET_COLOR
@ -30,17 +31,17 @@ class MarkdownExporter(TextExporter):
previous_line = '' previous_line = ''
warn_on_heading_level = False warn_on_heading_level = False
for line in body.splitlines(True): for line in body.splitlines(True):
if re.match(r"#+ ", line): if re.match(r"^#+ ", line):
"""ATX style headings""" """ATX style headings"""
newbody = newbody + previous_line + heading + line newbody = newbody + previous_line + heading + line
if re.match(r"#######+ ", heading + line): if re.match(r"^#######+ ", heading + line):
warn_on_heading_level = True warn_on_heading_level = True
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 H1""" """Setext style H1"""
newbody = newbody + heading + "# " + previous_line newbody = newbody + heading + "# " + previous_line
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""" """Setext style H2"""
newbody = newbody + heading + "## " + previous_line newbody = newbody + heading + "## " + previous_line
line = '' line = ''
@ -69,9 +70,11 @@ class MarkdownExporter(TextExporter):
if not e.date.year == year: if not e.date.year == year:
year = e.date.year year = e.date.year
out.append("# " + str(year)) out.append("# " + str(year))
out.append("")
if not e.date.month == month: if not e.date.month == month:
month = e.date.month month = e.date.month
out.append("## " + e.date.strftime("%B")) out.append("## " + e.date.strftime("%B"))
out.append("")
out.append(cls.export_entry(e, False)) out.append(cls.export_entry(e, False))
result = "\n".join(out) result = "\n".join(out)
return result return result