From 1c244da79bc8a639af397c19305b3e91a16f9ca3 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Mon, 15 Feb 2016 22:29:41 -0700 Subject: [PATCH] Add 'prjct' exporter. --- jrnl/__init__.py | 2 +- jrnl/plugins/prjct_exporter.py | 61 ++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 jrnl/plugins/prjct_exporter.py diff --git a/jrnl/__init__.py b/jrnl/__init__.py index 796c58c4..489492ff 100644 --- a/jrnl/__init__.py +++ b/jrnl/__init__.py @@ -8,7 +8,7 @@ jrnl is a simple journal application for your command line. from __future__ import absolute_import __title__ = 'jrnl' -__version__ = '2.0.0-rc1' +__version__ = '2.0.0-rc1.20150215' __author__ = 'Manuel Ebert' __license__ = 'MIT License' __copyright__ = 'Copyright 2013 - 2015 Manuel Ebert' diff --git a/jrnl/plugins/prjct_exporter.py b/jrnl/plugins/prjct_exporter.py new file mode 100644 index 00000000..d0098e4e --- /dev/null +++ b/jrnl/plugins/prjct_exporter.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# encoding: utf-8 + +from __future__ import absolute_import, unicode_literals, print_function +from .text_exporter import TextExporter +import sys +from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR + + +class PrjctExporter(TextExporter): + """This Exporter can convert entries and journals into Markdown formatted + text with front matter usable by the Ablog extention for Sphinx.""" + names = ["prjct"] + extension = "md" + + @classmethod + def export_entry(cls, entry, to_multifile=True): + """Returns a markdown representation of a single entry, with Ablog front matter.""" + if to_multifile is False: + print("{}ERROR{}: Prjct export must be to individual files. Please \ + specify a directory to export to.".format(ERROR_COLOR, RESET_COLOR, file=sys.stderr)) + return + + date_str = entry.date.strftime(entry.journal.config['timeformat']) + body_wrapper = "\n" if entry.body else "" + body = body_wrapper + entry.body + + # pass headings as is + + if len(entry.tags) > 0: + tags_str = ' :tags: ' + ', '.join([tag[1:] for tag in entry.tags]) + '\n' + else: + tags_str = '' + + if hasattr(entry, 'location'): + location_str = ' :location: {}\n'.format(entry.location.get('Locality', '')) + else: + location_str = '' + + # source directory is entry.journal.config['journal'] + # output directory is...? + + return "# {title}\n\n```eval_rst\n.. post:: {date}\n{tags}{category}{author}{location}{language}```\n\n{body}{space}" \ + .format( + date=date_str, + title=entry.title, + tags=tags_str, + category=" :category: jrnl\n", + author="", + location=location_str, + language="", + body=body, + space="\n" + ) + + @classmethod + def export_journal(cls, journal): + """Returns an error, as Prjct export requires a directory as a target.""" + print("{}ERROR{}: Prjct export must be to individual files. \ + Please specify a directory to export to.".format(ERROR_COLOR, RESET_COLOR), file=sys.stderr) + return