Change heading levels on Markdown export depending on if it is to a consolidated file or to individual files.

This commit is contained in:
MinchinWeb 2015-04-14 12:25:22 -06:00
parent 725257ca3d
commit 6cdf2f90c5
2 changed files with 9 additions and 4 deletions

View file

@ -11,14 +11,19 @@ class MarkdownExporter(TextExporter):
extension = "md"
@classmethod
def export_entry(cls, entry):
def export_entry(cls, entry, to_multifile=True):
"""Returns a markdown representation of a single entry."""
date_str = entry.date.strftime(entry.journal.config['timeformat'])
body_wrapper = "\n" if entry.body else ""
body = body_wrapper + entry.body
if to_multifile is True:
heading = '#'
else:
heading = '###'
return "{md} {date} {title} {body} {space}".format(
md="###",
md=heading,
date=date_str,
title=entry.title,
body=body,
@ -39,6 +44,6 @@ class MarkdownExporter(TextExporter):
month = e.date.month
out.append(e.date.strftime("%B"))
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)
return result

View file

@ -56,7 +56,7 @@ class TextExporter(BaseExporter):
representation as unicode if output is None."""
if output and os.path.isdir(output): # multiple files
return cls.write_files(journal, output)
elif output:
elif output: # single file
return cls.write_file(journal, output)
else:
return cls.export_journal(journal)