mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-11 17:18:30 +02:00
Change heading levels on Markdown export depending on if it is to a consolidated file or to individual files.
This commit is contained in:
parent
725257ca3d
commit
6cdf2f90c5
2 changed files with 9 additions and 4 deletions
|
@ -11,14 +11,19 @@ class MarkdownExporter(TextExporter):
|
||||||
extension = "md"
|
extension = "md"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def export_entry(cls, entry):
|
def export_entry(cls, entry, to_multifile=True):
|
||||||
"""Returns a markdown representation of a single entry."""
|
"""Returns a markdown representation of a single entry."""
|
||||||
date_str = entry.date.strftime(entry.journal.config['timeformat'])
|
date_str = entry.date.strftime(entry.journal.config['timeformat'])
|
||||||
body_wrapper = "\n" if entry.body else ""
|
body_wrapper = "\n" if entry.body else ""
|
||||||
body = body_wrapper + entry.body
|
body = body_wrapper + entry.body
|
||||||
|
|
||||||
|
if to_multifile is True:
|
||||||
|
heading = '#'
|
||||||
|
else:
|
||||||
|
heading = '###'
|
||||||
|
|
||||||
return "{md} {date} {title} {body} {space}".format(
|
return "{md} {date} {title} {body} {space}".format(
|
||||||
md="###",
|
md=heading,
|
||||||
date=date_str,
|
date=date_str,
|
||||||
title=entry.title,
|
title=entry.title,
|
||||||
body=body,
|
body=body,
|
||||||
|
@ -39,6 +44,6 @@ class MarkdownExporter(TextExporter):
|
||||||
month = e.date.month
|
month = e.date.month
|
||||||
out.append(e.date.strftime("%B"))
|
out.append(e.date.strftime("%B"))
|
||||||
out.append('-' * len(e.date.strftime("%B")) + "\n")
|
out.append('-' * len(e.date.strftime("%B")) + "\n")
|
||||||
out.append(cls.export_entry(e))
|
out.append(cls.export_entry(e, False))
|
||||||
result = "\n".join(out)
|
result = "\n".join(out)
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -56,7 +56,7 @@ class TextExporter(BaseExporter):
|
||||||
representation as unicode if output is None."""
|
representation as unicode if output is None."""
|
||||||
if output and os.path.isdir(output): # multiple files
|
if output and os.path.isdir(output): # multiple files
|
||||||
return cls.write_files(journal, output)
|
return cls.write_files(journal, output)
|
||||||
elif output:
|
elif output: # single file
|
||||||
return cls.write_file(journal, output)
|
return cls.write_file(journal, output)
|
||||||
else:
|
else:
|
||||||
return cls.export_journal(journal)
|
return cls.export_journal(journal)
|
||||||
|
|
Loading…
Add table
Reference in a new issue