How to use the jrnl.plugins.text_exporter.TextExporter function in jrnl

To help you get started, we’ve selected a few jrnl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jrnl-org / jrnl / jrnl / plugins / markdown_exporter.py View on Github external
#!/usr/bin/env python
# encoding: utf-8

from .text_exporter import TextExporter
import os
import re
import sys
from ..util import WARNING_COLOR, RESET_COLOR


class MarkdownExporter(TextExporter):
    """This Exporter can convert entries and journals into Markdown."""

    names = ["md", "markdown"]
    extension = "md"

    @classmethod
    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 = "###"
github jrnl-org / jrnl / jrnl / plugins / fancy_exporter.py View on Github external
#!/usr/bin/env python
# encoding: utf-8

from __future__ import absolute_import, unicode_literals, print_function
from .text_exporter import TextExporter
from textwrap import TextWrapper


class FancyExporter(TextExporter):
    """This Exporter can convert entries and journals into text with unicode box drawing characters."""

    names = ["fancy", "boxed"]
    extension = "txt"

    border_a = "┎"
    border_b = "─"
    border_c = "╮"
    border_d = "╘"
    border_e = "═"
    border_f = "╕"
    border_g = "┃"
    border_h = "│"
    border_i = "┠"
    border_j = "╌"
    border_k = "┤"
github jrnl-org / jrnl / jrnl / plugins / template_exporter.py View on Github external
#!/usr/bin/env python
# encoding: utf-8

from .text_exporter import TextExporter
from .template import Template
import os
from glob import glob


class GenericTemplateExporter(TextExporter):
    """This Exporter can convert entries and journals into text files."""

    @classmethod
    def export_entry(cls, entry):
        """Returns a string representation of a single entry."""
        vars = {"entry": entry, "tags": entry.tags}
        return cls.template.render_block("entry", **vars)

    @classmethod
    def export_journal(cls, journal):
        """Returns a string representation of an entire journal."""
        vars = {"journal": journal, "entries": journal.entries, "tags": journal.tags}
        return cls.template.render_block("journal", **vars)


def __exporter_from_file(template_file):
github jrnl-org / jrnl / jrnl / plugins / tag_exporter.py View on Github external
#!/usr/bin/env python
# encoding: utf-8

from .text_exporter import TextExporter
from .util import get_tags_count


class TagExporter(TextExporter):
    """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 list of tags for a single entry."""
        return ", ".join(entry.tags)

    @classmethod
    def export_journal(cls, journal):
        """Returns a list of tags and their frequency for an entire journal."""
        tag_counts = get_tags_count(journal)
        result = ""
        if not tag_counts:
github jrnl-org / jrnl / jrnl / plugins / json_exporter.py View on Github external
#!/usr/bin/env python
# encoding: utf-8

from .text_exporter import TextExporter
import json
from .util import get_tags_count


class JSONExporter(TextExporter):
    """This Exporter can convert entries and journals into json."""

    names = ["json"]
    extension = "json"

    @classmethod
    def entry_to_dict(cls, entry):
        entry_dict = {
            "title": entry.title,
            "body": entry.body,
            "date": entry.date.strftime("%Y-%m-%d"),
            "time": entry.date.strftime("%H:%M"),
            "starred": entry.starred,
        }
        if hasattr(entry, "uuid"):
            entry_dict["uuid"] = entry.uuid
github jrnl-org / jrnl / jrnl / plugins / __init__.py View on Github external
from .text_exporter import TextExporter
from .jrnl_importer import JRNLImporter
from .json_exporter import JSONExporter
from .markdown_exporter import MarkdownExporter
from .tag_exporter import TagExporter
from .xml_exporter import XMLExporter
from .yaml_exporter import YAMLExporter
from .template_exporter import __all__ as template_exporters
from .fancy_exporter import FancyExporter

__exporters = [
    JSONExporter,
    MarkdownExporter,
    TagExporter,
    TextExporter,
    XMLExporter,
    YAMLExporter,
    FancyExporter,
] + template_exporters
__importers = [JRNLImporter]

__exporter_types = {name: plugin for plugin in __exporters for name in plugin.names}
__importer_types = {name: plugin for plugin in __importers for name in plugin.names}

EXPORT_FORMATS = sorted(__exporter_types.keys())
IMPORT_FORMATS = sorted(__importer_types.keys())


def get_exporter(format):
    for exporter in __exporters:
        if hasattr(exporter, "names") and format in exporter.names:
github jrnl-org / jrnl / jrnl / plugins / yaml_exporter.py View on Github external
#!/usr/bin/env python
# encoding: utf-8

from .text_exporter import TextExporter
import os
import re
import sys
from ..util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR


class YAMLExporter(TextExporter):
    """This Exporter can convert entries and journals into Markdown formatted text 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,
            )