Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to hashmark Markdown headers on export (Mk II) #639

Merged
merged 3 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions features/exporting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 9 additions & 8 deletions jrnl/plugins/markdown_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -30,17 +31,17 @@ def export_entry(cls, entry, to_multifile=True):
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 = ''
Expand Down Expand Up @@ -68,12 +69,12 @@ def export_journal(cls, journal):
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))
out.append("")
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("")
out.append(cls.export_entry(e, False))
result = "\n".join(out)
return result
9 changes: 5 additions & 4 deletions jrnl/plugins/yaml_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,17 +35,17 @@ def export_entry(cls, entry, to_multifile=True):
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 = ''
Expand Down