mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-01 22:56:12 +02:00
Add 'prjct' exporter.
This commit is contained in:
parent
b84bc9b856
commit
1c244da79b
2 changed files with 62 additions and 1 deletions
|
@ -8,7 +8,7 @@ jrnl is a simple journal application for your command line.
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
__title__ = 'jrnl'
|
__title__ = 'jrnl'
|
||||||
__version__ = '2.0.0-rc1'
|
__version__ = '2.0.0-rc1.20150215'
|
||||||
__author__ = 'Manuel Ebert'
|
__author__ = 'Manuel Ebert'
|
||||||
__license__ = 'MIT License'
|
__license__ = 'MIT License'
|
||||||
__copyright__ = 'Copyright 2013 - 2015 Manuel Ebert'
|
__copyright__ = 'Copyright 2013 - 2015 Manuel Ebert'
|
||||||
|
|
61
jrnl/plugins/prjct_exporter.py
Normal file
61
jrnl/plugins/prjct_exporter.py
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue