# Path: scribbler/errors.py
# class ScribblerWarning(Warning):
#     pass
# 
# class ScribblerError(Exception):
#     pass
# 
# Path: scribbler/content.py
# class ScribblerContent(object):
#     """
#     Class representing Note and Appendix objects. Must pass the name of
#     the note/appendix, the date it is for, the path to its source file,
#     relative to notebook's notes directory, and the notebook object which
#     contains it.
#     """
#     def __init__(self, name, date, src_path, notebook):
#         self.notebook = notebook
#         self.name = name
#         self.date = date
#         basename = os.path.basename(src_path)
#         for ext in ['md', 'rst', 'html']:
#             if basename.endswith(ext):
#                 self.markup = ext
#                 self.slug = basename[:len(basename)-len(ext)-1]
#                 break
#         else:
#             raise ScribblerError("Unrecognized extension for file '{}'".format(basename))
#         self.src_path = src_path
#         self.html_path = None
#         self.pdf_path = None
#         self.update()
#     
#     def _pdf_path(self):
#         """
#         Returns the path where a PDF file is expected to be, relative to
#         the notebook root.
#         """
#         return os.path.join(self.notebook.PDF_DIR, str(self.slug) + '.pdf')
#     
#     def _html_path(self):
#         """
#         Returns the path where an HTML file is expected to be, relative to
#         the notebook root.
#         """
#         if os.path.basename(os.path.dirname(self.src_path)) == self.notebook.NOTE_DIR:
#             return os.path.join(self.notebook.HTML_DIR, self.notebook.NOTE_DIR, str(self.slug) + '.html')
#         else:
#             return os.path.join(self.notebook.HTML_DIR, 'pages', str(self.slug) + '.html')
#     
#     def update(self):
#         """
#         Updates information about the content.
#         """
#         if not os.path.isfile(os.path.join(self.notebook.location, self.src_path)):
#             raise ScribblerError("Note with path '{}' does not exist".format(self.src_path))
#         self.src_date = os.path.getmtime(os.path.join(self.notebook.location,
#                                          self.src_path))
#         if os.path.isfile(os.path.join(self.notebook.location, self._html_path())):
#             self.html_path = self._html_path()
#         else:
#             self.html_path = None
#         if os.path.isfile(os.path.join(self.notebook.location, self._pdf_path())):
#             self.pdf_path = self._pdf_path()
#             self.pdf_date = os.path.getmtime(os.path.join(self.notebook.location,
#                                              self.pdf_path))
#         else:
#             self.pdf_path = None
#             self.pdf_date = 0
#         
#     def make_pdf(self):
#         """
#         Produces a PDF version of the content from its HTML version, if
#         it requires updating or does not already exist.
#         """
#         src = os.path.join(self.notebook.location, self.html_path)
#         dest = os.path.join(self.notebook.location, self._pdf_path())
#         pdfkit.from_file(src, dest, options=self.notebook.pdf_settings)


import os.path
import subprocess
import shutil
import yaml
import pdfkit
from copy import copy
from datetime import date, datetime
from pickle import dump, load
from glob import glob
from pelican.utils import slugify
from scribbler.PyPDF2 import PdfFileMerger
from .errors import ScribblerWarning, ScribblerError
from .content import ScribblerContent
            rpath = path
        else:
            if dest.endswith(os.path.sep):
                rpath = os.path.relpath(os.path.abspath(path), dest[:len(os.path.sep)])
            else:
                rpath = os.path.relpath(os.path.abspath(path), os.path.dirname(dest))
        os.symlink(rpath, dest)

    def newnote(self, date, title, markup='md'):
        """
        Create a new note with the specified date and title. Returns the
        path to that note.
        """
        MARKUP_OPTIONS = {
            'md': "Title: {0}\nDate: {1}\nTags: \n\n",
            'rst': "{0}\n###################\n\n:date: {1}\n:tags: \n\n",
            'html': "<html>\n\t<head>\n\t\t<title>{0}</title>\n\t\t"
                    "<meta name='date' content='{1}' />\n\t\t"
                    "<meta name='tags' content=' ' />\n\t</head>"
                    "\n\t<body>\n\t\t\n\t</body>\n</html>\n",
        }
        try:
            datetime.strptime(date, '%Y-%m-%d %H:%M')
        except:
            raise ScribblerError('Incorrectly formatted date; date format '
                             'should be YYYY-MM-DD HH:mm')
        name = date.split()[0] + '-' + slugify(title)
        for ext in MARKUP_OPTIONS:
            if os.path.isfile(os.path.join(self.location,self.NOTE_DIR,
                              name + '.' + ext)):

# Path: scribbler/errors.py
# class ScribblerWarning(Warning):
#     pass
# 
# class ScribblerError(Exception):
#     pass
# 
# Path: scribbler/content.py
# class ScribblerContent(object):
#     """
#     Class representing Note and Appendix objects. Must pass the name of
#     the note/appendix, the date it is for, the path to its source file,
#     relative to notebook's notes directory, and the notebook object which
#     contains it.
#     """
#     def __init__(self, name, date, src_path, notebook):
#         self.notebook = notebook
#         self.name = name
#         self.date = date
#         basename = os.path.basename(src_path)
#         for ext in ['md', 'rst', 'html']:
#             if basename.endswith(ext):
#                 self.markup = ext
#                 self.slug = basename[:len(basename)-len(ext)-1]
#                 break
#         else:
#             raise ScribblerError("Unrecognized extension for file '{}'".format(basename))
#         self.src_path = src_path
#         self.html_path = None
#         self.pdf_path = None
#         self.update()
#     
#     def _pdf_path(self):
#         """
#         Returns the path where a PDF file is expected to be, relative to
#         the notebook root.
#         """
#         return os.path.join(self.notebook.PDF_DIR, str(self.slug) + '.pdf')
#     
#     def _html_path(self):
#         """
#         Returns the path where an HTML file is expected to be, relative to
#         the notebook root.
#         """
#         if os.path.basename(os.path.dirname(self.src_path)) == self.notebook.NOTE_DIR:
#             return os.path.join(self.notebook.HTML_DIR, self.notebook.NOTE_DIR, str(self.slug) + '.html')
#         else:
#             return os.path.join(self.notebook.HTML_DIR, 'pages', str(self.slug) + '.html')
#     
#     def update(self):
#         """
#         Updates information about the content.
#         """
#         if not os.path.isfile(os.path.join(self.notebook.location, self.src_path)):
#             raise ScribblerError("Note with path '{}' does not exist".format(self.src_path))
#         self.src_date = os.path.getmtime(os.path.join(self.notebook.location,
#                                          self.src_path))
#         if os.path.isfile(os.path.join(self.notebook.location, self._html_path())):
#             self.html_path = self._html_path()
#         else:
#             self.html_path = None
#         if os.path.isfile(os.path.join(self.notebook.location, self._pdf_path())):
#             self.pdf_path = self._pdf_path()
#             self.pdf_date = os.path.getmtime(os.path.join(self.notebook.location,
#                                              self.pdf_path))
#         else:
#             self.pdf_path = None
#             self.pdf_date = 0
#         
#     def make_pdf(self):
#         """
#         Produces a PDF version of the content from its HTML version, if
#         it requires updating or does not already exist.
#         """
#         src = os.path.join(self.notebook.location, self.html_path)
#         dest = os.path.join(self.notebook.location, self._pdf_path())
#         pdfkit.from_file(src, dest, options=self.notebook.pdf_settings)


# Path: scribbler/notebook.py
import os.path
import subprocess
import shutil
import yaml
import pdfkit
from copy import copy
from datetime import date, datetime
from pickle import dump, load
from glob import glob
from pelican.utils import slugify
from scribbler.PyPDF2 import PdfFileMerger
from .errors import ScribblerWarning, ScribblerError
from .content import ScribblerContent

            rpath = path
        else:
            if dest.endswith(os.path.sep):
                rpath = os.path.relpath(os.path.abspath(path), dest[:len(os.path.sep)])
            else:
                rpath = os.path.relpath(os.path.abspath(path), os.path.dirname(dest))
        os.symlink(rpath, dest)

    def newnote(self, date, title, markup='md'):
        """
        Create a new note with the specified date and title. Returns the
        path to that note.
        """
        MARKUP_OPTIONS = {
            'md': "Title: {0}\nDate: {1}\nTags: \n\n",
            'rst': "{0}\n###################\n\n:date: {1}\n:tags: \n\n",
            'html': "<html>\n\t<head>\n\t\t<title>{0}</title>\n\t\t"
                    "<meta name='date' content='{1}' />\n\t\t"
                    "<meta name='tags' content=' ' />\n\t</head>"
                    "\n\t<body>\n\t\t\n\t</body>\n</html>\n",
        }
        try:
            datetime.strptime(date, '%Y-%m-%d %H:%M')
        except:
            raise ScribblerError('Incorrectly formatted date; date format '
                             'should be YYYY-MM-DD HH:mm')
        name = date.split()[0] + '-' + slugify(title)
        for ext in MARKUP_OPTIONS:
            if os.path.isfile(os.path.join(self.location,self.NOTE_DIR,
                              name + '.' + ext)):

                raise ScribblerError('Date and name produce slug the '