mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-11 17:18:30 +02:00
[YAML Export] style improvements
This commit is contained in:
parent
cccdc157fb
commit
a31eb9628a
1 changed files with 8 additions and 5 deletions
|
@ -17,7 +17,8 @@ class YAMLExporter(TextExporter):
|
||||||
def export_entry(cls, entry, to_multifile=True):
|
def export_entry(cls, entry, to_multifile=True):
|
||||||
"""Returns a markdown representation of a single entry, with YAML front matter."""
|
"""Returns a markdown representation of a single entry, with YAML front matter."""
|
||||||
if to_multifile is False:
|
if to_multifile is False:
|
||||||
print("{}ERROR{}: YAML export must be to individual files. Please specify a directory to export to.".format("\033[31m", "\033[0m", file=sys.stderr))
|
print("{}ERROR{}: YAML export must be to individual files. Please \
|
||||||
|
specify a directory to export to.".format(ERROR_COLOR, RESET_COLOR, file=sys.stderr))
|
||||||
return
|
return
|
||||||
|
|
||||||
date_str = entry.date.strftime(entry.journal.config['timeformat'])
|
date_str = entry.date.strftime(entry.journal.config['timeformat'])
|
||||||
|
@ -28,12 +29,12 @@ class YAMLExporter(TextExporter):
|
||||||
# see also Entry.Entry.rag_regex
|
# see also Entry.Entry.rag_regex
|
||||||
multi_tag_regex = re.compile(r'(?u)^\s*([{tags}][-+*#/\w]+\s*)+$'.format(tags=tagsymbols), re.UNICODE)
|
multi_tag_regex = re.compile(r'(?u)^\s*([{tags}][-+*#/\w]+\s*)+$'.format(tags=tagsymbols), re.UNICODE)
|
||||||
|
|
||||||
'''Increase heading levels in body text'''
|
"""Increase heading levels in body text"""
|
||||||
newbody = ''
|
newbody = ''
|
||||||
heading = '#'
|
heading = '#'
|
||||||
previous_line = ''
|
previous_line = ''
|
||||||
warn_on_heading_level = False
|
warn_on_heading_level = False
|
||||||
for line in entry.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
|
||||||
|
@ -57,7 +58,8 @@ class YAMLExporter(TextExporter):
|
||||||
newbody = newbody + previous_line # add very last line
|
newbody = newbody + previous_line # add very last line
|
||||||
|
|
||||||
if warn_on_heading_level is True:
|
if warn_on_heading_level is True:
|
||||||
print("{}WARNING{}: Headings increased past H6 on export - {} {}".format(WARNING_COLOR, RESET_COLOR, date_str, entry.title), file=sys.stderr)
|
print("{}WARNING{}: Headings increased past H6 on export - {} {}" \
|
||||||
|
.format(WARNING_COLOR, RESET_COLOR, date_str, entry.title), file=sys.stderr)
|
||||||
|
|
||||||
dayone_attributes = ''
|
dayone_attributes = ''
|
||||||
if hasattr(entry, "uuid"):
|
if hasattr(entry, "uuid"):
|
||||||
|
@ -79,5 +81,6 @@ class YAMLExporter(TextExporter):
|
||||||
@classmethod
|
@classmethod
|
||||||
def export_journal(cls, journal):
|
def export_journal(cls, journal):
|
||||||
"""Returns an error, as YAML export requires a directory as a target."""
|
"""Returns an error, as YAML export requires a directory as a target."""
|
||||||
print("{}ERROR{}: YAML export must be to individual files. Please specify a directory to export to.".format(ERROR_COLOR, RESET_COLOR), file=sys.stderr)
|
print("{}ERROR{}: YAML export must be to individual files. \
|
||||||
|
Please specify a directory to export to.".format(ERROR_COLOR, RESET_COLOR), file=sys.stderr)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue