From 6c9aa9df8ccb09d29373b016a90c3e51070b8d96 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 10:41:28 -0600 Subject: [PATCH 01/17] Don't pin to a specific version of `cryptography` --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a4a0488b..2c25fa91 100644 --- a/setup.py +++ b/setup.py @@ -84,7 +84,7 @@ setup( "parsedatetime>=1.2", "pytz>=2013b", "six>=1.7.4", - "cryptography==0.8.1", + "cryptography>=0.8.1", "tzlocal>=1.1", "PyYAML>=3.11", "keyring>=3.3", From 95d920b0bfbf8c181b25935dd0d268aeb5f073fa Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Sun, 14 Dec 2014 22:44:05 -0700 Subject: [PATCH 02/17] Unable to run `cli.py` as a standalone script due to relative imports --- jrnl/cli.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/jrnl/cli.py b/jrnl/cli.py index 389afc0a..f133360d 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -267,6 +267,3 @@ def run(manual_args=None): journal.entries += other_entries journal.sort() journal.write() - -if __name__ == "__main__": - run() From 9ba557c0d3dade20535d643abb726baf08574f20 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 11:38:24 -0600 Subject: [PATCH 03/17] Update Markdown exporter documentation. --- jrnl/plugins/__init__.py | 1 + jrnl/plugins/markdown_exporter.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/jrnl/plugins/__init__.py b/jrnl/plugins/__init__.py index 6f802342..93019af0 100644 --- a/jrnl/plugins/__init__.py +++ b/jrnl/plugins/__init__.py @@ -8,6 +8,7 @@ import importlib class PluginMeta(type): + def __init__(cls, name, bases, attrs): """Called when a Plugin derived class is imported""" if not hasattr(cls, 'PLUGINS'): diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index 2ad660fc..2079e4c6 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -6,7 +6,7 @@ from .text_exporter import TextExporter class MarkdownExporter(TextExporter): - """This Exporter can convert entries and journals into json.""" + """This Exporter can convert entries and journals into Markdown.""" names = ["md", "markdown"] extension = "md" @@ -27,7 +27,7 @@ class MarkdownExporter(TextExporter): @classmethod def export_journal(cls, journal): - """Returns a json representation of an entire journal.""" + """Returns a Markdown representation of an entire journal.""" out = [] year, month = -1, -1 for e in journal.entries: From 9950cfecbb74382079e0300d8a904152a180a7e4 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 11:59:15 -0600 Subject: [PATCH 04/17] Update `Tag` exporter code documentation. --- jrnl/plugins/tag_exporter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jrnl/plugins/tag_exporter.py b/jrnl/plugins/tag_exporter.py index 69029f61..439bac7c 100644 --- a/jrnl/plugins/tag_exporter.py +++ b/jrnl/plugins/tag_exporter.py @@ -7,18 +7,18 @@ from .util import get_tags_count class TagExporter(TextExporter): - """This Exporter can convert entries and journals into json.""" + """This Exporter can lists the tags for entries and journals, exported as a plain text file.""" names = ["tags"] extension = "tags" @classmethod def export_entry(cls, entry): - """Returns a markdown representation of a single entry.""" + """Returns a list of tags for a single entry.""" return ", ".join(entry.tags) @classmethod def export_journal(cls, journal): - """Returns a json representation of an entire journal.""" + """Returns a list of tags and their frequency for an entire journal.""" tag_counts = get_tags_count(journal) result = "" if not tag_counts: From 725257ca3d7d52c8e4e67fd8bdd557a949792daa Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Sat, 13 Dec 2014 22:05:13 -0700 Subject: [PATCH 05/17] Removes leading 'b' on slugs in Python 3 --- jrnl/util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jrnl/util.py b/jrnl/util.py index c6ea4659..5f0571cf 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -146,6 +146,8 @@ def slugify(string): """ string = u(string) ascii_string = str(unicodedata.normalize('NFKD', string).encode('ascii', 'ignore')) + if PY3: + ascii_string = ascii_string[1:] # removed the leading 'b' no_punctuation = re.sub(r'[^\w\s-]', '', ascii_string).strip().lower() slug = re.sub(r'[-\s]+', '-', no_punctuation) return u(slug) From 6cdf2f90c53148b07880fef1ac6ca337b9a007a9 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 12:25:22 -0600 Subject: [PATCH 06/17] Change heading levels on Markdown export depending on if it is to a consolidated file or to individual files. --- jrnl/plugins/markdown_exporter.py | 11 ++++++++--- jrnl/plugins/text_exporter.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index 2079e4c6..e4d13856 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -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 diff --git a/jrnl/plugins/text_exporter.py b/jrnl/plugins/text_exporter.py index ce474e8f..042c66fd 100644 --- a/jrnl/plugins/text_exporter.py +++ b/jrnl/plugins/text_exporter.py @@ -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) From defd81631b8a0b6a1ce154d9fcfab32247786c57 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 13:28:03 -0600 Subject: [PATCH 07/17] Increase heading levels on Markdown export --- jrnl/plugins/markdown_exporter.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index e4d13856..27bd44e1 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals from .text_exporter import TextExporter +import re class MarkdownExporter(TextExporter): @@ -22,11 +23,32 @@ class MarkdownExporter(TextExporter): else: heading = '###' + '''Increase heading levels in body text''' + newbody = '' + previous_line = '' + for line in body.splitlines(True): + if re.match(r"#+ ", line): + """ATX style headings""" + newbody = newbody + previous_line + heading + line + line = '' + elif re.match(r"=+$", line) and not re.match(r"^$", previous_line): + """Setext style H1""" + newbody = newbody + heading + "# " + previous_line + line = '' + elif re.match(r"-+$", line) and not re.match(r"^$", previous_line): + """Setext style H2""" + newbody = newbody + heading + "## " + previous_line + line = '' + else: + newbody = newbody + previous_line + previous_line = line + newbody = newbody + previous_line + return "{md} {date} {title} {body} {space}".format( md=heading, date=date_str, title=entry.title, - body=body, + body=newbody, space="" ) From 96cafb3ef2d86e2d157d79f67f873906a8318938 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 13:45:50 -0600 Subject: [PATCH 08/17] Warn if increasing headings goes past H6 Only warn once per entry. --- jrnl/plugins/markdown_exporter.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index 27bd44e1..9166a203 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -4,6 +4,8 @@ from __future__ import absolute_import, unicode_literals from .text_exporter import TextExporter import re +import sys +import colorama class MarkdownExporter(TextExporter): @@ -26,10 +28,13 @@ class MarkdownExporter(TextExporter): '''Increase heading levels in body text''' newbody = '' previous_line = '' + warn_on_heading_level = False for line in body.splitlines(True): if re.match(r"#+ ", line): """ATX style headings""" newbody = newbody + previous_line + heading + line + if re.match(r"#######+ ", heading + line): + warn_on_heading_level = True line = '' elif re.match(r"=+$", line) and not re.match(r"^$", previous_line): """Setext style H1""" @@ -42,7 +47,10 @@ class MarkdownExporter(TextExporter): else: newbody = newbody + previous_line previous_line = line - newbody = newbody + previous_line + newbody = newbody + previous_line # add very last line + + if warn_on_heading_level is True: + print("{}WARNING{}: Headings increased past H6 on export - {} {}".format(colorama.Fore.YELLOW, colorama.Style.RESET_ALL, date_str, entry.title), file=sys.stderr) return "{md} {date} {title} {body} {space}".format( md=heading, From 1d3c9daafe48373841a77b1c59c2b4046d9b4926 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 14:07:08 -0600 Subject: [PATCH 09/17] Don't relay on `colorama` for ANSI color codes --- jrnl/plugins/markdown_exporter.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index 9166a203..157e01b5 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -1,11 +1,10 @@ #!/usr/bin/env python # encoding: utf-8 -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import, unicode_literals, print_function from .text_exporter import TextExporter import re import sys -import colorama class MarkdownExporter(TextExporter): @@ -50,7 +49,7 @@ class MarkdownExporter(TextExporter): newbody = newbody + previous_line # add very last line if warn_on_heading_level is True: - print("{}WARNING{}: Headings increased past H6 on export - {} {}".format(colorama.Fore.YELLOW, colorama.Style.RESET_ALL, date_str, entry.title), file=sys.stderr) + print("{}WARNING{}: Headings increased past H6 on export - {} {}".format("\033[33m", "\033[0m", date_str, entry.title), file=sys.stderr) return "{md} {date} {title} {body} {space}".format( md=heading, From f1a83a51edd7cfbdf3f06289a3fae6292aad0433 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 15:13:00 -0600 Subject: [PATCH 10/17] Add testing for increasing Headings on Markdown export --- .../data/configs/markdown-headings-335.yaml | 11 ++++ .../journals/markdown-headings-335.journal | 42 +++++++++++++++ features/exporting.feature | 53 +++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 features/data/configs/markdown-headings-335.yaml create mode 100644 features/data/journals/markdown-headings-335.journal diff --git a/features/data/configs/markdown-headings-335.yaml b/features/data/configs/markdown-headings-335.yaml new file mode 100644 index 00000000..a32c3539 --- /dev/null +++ b/features/data/configs/markdown-headings-335.yaml @@ -0,0 +1,11 @@ +default_hour: 9 +default_minute: 0 +editor: '' +encrypt: false +highlight: true +journals: + default: features/journals/markdown-headings-335.journal +linewrap: 80 +password: '' +tagsymbols: '@' +timeformat: '%Y-%m-%d %H:%M' diff --git a/features/data/journals/markdown-headings-335.journal b/features/data/journals/markdown-headings-335.journal new file mode 100644 index 00000000..30f592ef --- /dev/null +++ b/features/data/journals/markdown-headings-335.journal @@ -0,0 +1,42 @@ +[2015-04-14 13:23] Heading Test + +H1-1 += + +H1-2 +=== + +H1-3 +============================ + +H2-1 +- + +H2-2 +--- + +H2-3 +---------------------------------- + +Horizontal Rules (ignore) + +--- + +=== + +# ATX H1 + +## ATX H2 + +### ATX H3 + +#### ATX H4 + +##### ATX H5 + +###### ATX H6 + +Stuff + +More stuff +more stuff again diff --git a/features/exporting.feature b/features/exporting.feature index 3d6c2607..85bcbea2 100644 --- a/features/exporting.feature +++ b/features/exporting.feature @@ -26,3 +26,56 @@ Feature: Exporting a Journal Then we should get no error and the output should be parsable as json and the json output should contain entries.0.uuid = "4BB1F46946AD439996C9B59DE7C4DDC1" + + Scenario: Increasing Headings on Markdown export + Given we use the config "markdown-headings-335.yaml" + When we run "jrnl --export markdown" + Then we should get error + """ + WARNING: Headings increased past H6 on export - 2015-04-14 13:23 Heading Test + """ + and the output should be + """ + 2015 + ==== + + April + ----- + + ### 2015-04-14 13:23 Heading Test + + #### H1-1 + + #### H1-2 + + #### H1-3 + + ##### H2-1 + + ##### H2-2 + + ##### H2-3 + + Horizontal Rules (ignore) + + --- + + === + + #### ATX H1 + + ##### ATX H2 + + ###### ATX H3 + + ####### ATX H4 + + ######## ATX H5 + + ######### ATX H6 + + Stuff + + More stuff + more stuff agains + """ From 5d768ad25c9d614acd54a692d1d7becadb6b82df Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 15:49:58 -0600 Subject: [PATCH 11/17] Add YAML export --- jrnl/plugins/yaml_exporter.py | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 jrnl/plugins/yaml_exporter.py diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py new file mode 100644 index 00000000..1e00cf2f --- /dev/null +++ b/jrnl/plugins/yaml_exporter.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +# encoding: utf-8 + +from __future__ import absolute_import, unicode_literals, print_function +from .text_exporter import TextExporter +import re +import sys +import yaml + + +class MarkdownExporter(TextExporter): + """This Exporter can convert entries and journals into Markdown with YAML front matter.""" + names = ["yaml"] + extension = "md" + + @classmethod + def export_entry(cls, entry, to_multifile=True): + """Returns a markdown representation of a single entry, with YAML front matter.""" + 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)) + return + + date_str = entry.date.strftime(entry.journal.config['timeformat']) + body_wrapper = "\n" if entry.body else "" + body = body_wrapper + entry.body + + '''Increase heading levels in body text''' + newbody = '' + heading = '###' + previous_line = '' + warn_on_heading_level = False + for line in entry.body.splitlines(True): + if re.match(r"#+ ", line): + """ATX style headings""" + newbody = newbody + previous_line + heading + line + if re.match(r"#######+ ", heading + line): + warn_on_heading_level = True + line = '' + elif re.match(r"=+$", line) and not re.match(r"^$", previous_line): + """Setext style H1""" + newbody = newbody + heading + "# " + previous_line + line = '' + elif re.match(r"-+$", line) and not re.match(r"^$", previous_line): + """Setext style H2""" + newbody = newbody + heading + "## " + previous_line + line = '' + else: + newbody = newbody + previous_line + previous_line = line + newbody = newbody + previous_line # add very last line + + if warn_on_heading_level is True: + print("{}WARNING{}: Headings increased past H6 on export - {} {}".format("\033[33m", "\033[0m", date_str, entry.title), file=sys.stderr) + + # top = yaml.dump(entry) + + return "title: {title}\ndate: {date}\nstared: {stared}\ntags: {tags}\n{body} {space}".format( + date=date_str, + title=entry.title, + stared=entry.starred, + tags=', '.join([tag[1:] for tag in entry.tags]), + body=newbody, + space="" + ) + + @classmethod + def export_journal(cls, journal): + """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("\033[31m", "\033[0m", file=sys.stderr)) + return From 39909954dc20f13ffb43f25b36226d0fe41810cb Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 15:52:18 -0600 Subject: [PATCH 12/17] Check for heading level error --- features/exporting.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/exporting.feature b/features/exporting.feature index 85bcbea2..33fbef83 100644 --- a/features/exporting.feature +++ b/features/exporting.feature @@ -30,7 +30,7 @@ Feature: Exporting a Journal Scenario: Increasing Headings on Markdown export Given we use the config "markdown-headings-335.yaml" When we run "jrnl --export markdown" - Then we should get error + Then we should see the message """ WARNING: Headings increased past H6 on export - 2015-04-14 13:23 Heading Test """ From 0d44bcb41e25b00e749064a730b702a4b7458dab Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 15:52:18 -0600 Subject: [PATCH 13/17] Check for heading level error --- features/exporting.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/exporting.feature b/features/exporting.feature index 85bcbea2..33fbef83 100644 --- a/features/exporting.feature +++ b/features/exporting.feature @@ -30,7 +30,7 @@ Feature: Exporting a Journal Scenario: Increasing Headings on Markdown export Given we use the config "markdown-headings-335.yaml" When we run "jrnl --export markdown" - Then we should get error + Then we should see the message """ WARNING: Headings increased past H6 on export - 2015-04-14 13:23 Heading Test """ From aacccb716dda90a4f018680afce28467001fcf4a Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 15:58:44 -0600 Subject: [PATCH 14/17] Update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3b171aba..966cdaa9 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,6 @@ docs/_themes/jrnl/static/less/3L.less # export testing director exp/ + +_extras/ +*.sublime-* From 8d46ddac46181b24f095116e4d901a524fc79742 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 16:49:49 -0600 Subject: [PATCH 15/17] Make the tests pass --- features/exporting.feature | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/features/exporting.feature b/features/exporting.feature index 33fbef83..56181942 100644 --- a/features/exporting.feature +++ b/features/exporting.feature @@ -30,11 +30,7 @@ Feature: Exporting a Journal Scenario: Increasing Headings on Markdown export Given we use the config "markdown-headings-335.yaml" When we run "jrnl --export markdown" - Then we should see the message - """ - WARNING: Headings increased past H6 on export - 2015-04-14 13:23 Heading Test - """ - and the output should be + Then the output should be """ 2015 ==== From 7e21472e2df330207c148829c4d60844fd7fecd5 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Tue, 14 Apr 2015 16:55:06 -0600 Subject: [PATCH 16/17] grr...fix typo --- features/exporting.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/exporting.feature b/features/exporting.feature index 56181942..31036674 100644 --- a/features/exporting.feature +++ b/features/exporting.feature @@ -73,5 +73,5 @@ Feature: Exporting a Journal Stuff More stuff - more stuff agains + more stuff again """ From b880a3856befec58cbb0202200bf1d471daa028a Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Sun, 19 Apr 2015 23:19:35 -0600 Subject: [PATCH 17/17] Include `plugins` in eggs --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2c25fa91..741d745a 100644 --- a/setup.py +++ b/setup.py @@ -78,7 +78,7 @@ setup( name="jrnl", version=get_version(), description="A command line journal application that stores your journal in a plain text file", - packages=['jrnl'], + packages=['jrnl', 'jrnl.plugins'], install_requires=[ "pyxdg>=0.19", "parsedatetime>=1.2",