From 28136071814c43a8e31ae2ef6c5578597eb9264e Mon Sep 17 00:00:00 2001 From: Stephan Gabler Date: Fri, 10 Aug 2012 22:13:05 +0200 Subject: [PATCH] replace the original image name by markdown syntax for an inline image --- .gitignore | 2 ++ jrnl/Journal.py | 7 ++++++- tests/test_data/url_test.txt | 2 +- tests/test_jrnl.py | 7 ++++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a36e2fbb..d5c0c910 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ lib64 # Installer logs pip-log.txt + +.DS_Store diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 76b028a9..03071822 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -251,7 +251,7 @@ class Journal: def parse_for_images(self, body): # TODO: parse also for name (like used in markdown [name](url)) - + found_images = [] for word in body.split(): res = self.path_search.match(word) if res and os.path.exists(res.groups()[0]): @@ -259,6 +259,11 @@ class Journal: ext = os.path.splitext(os.path.basename(im_path))[1] random_name = 'img_' + self._random_string() + ext shutil.copyfile(im_path, os.path.join(self.data_path, random_name)) + found_images.append((im_path, random_name)) + for im_path, random_name in found_images: + body = re.sub('[\[\(]?%s[\[\(]?' % im_path, + '![%s](%s)' % (os.path.basename(im_path), random_name), + body) return body def new_entry(self, raw, date=None): diff --git a/tests/test_data/url_test.txt b/tests/test_data/url_test.txt index bf899bb3..2fe13cd0 100644 --- a/tests/test_data/url_test.txt +++ b/tests/test_data/url_test.txt @@ -1,5 +1,5 @@ ein normalser satz. -Lorem ipsum dolor sit amet, consectetur adipisicing elit, (/Volumes/dedan/bla.png) sed do eiusmod tempor incididunt ut (http://en.wikipedia.org/wiki/Generative_model) labore et dolore magna aliqua. Ut enim ad minim veniam, (/Users/dedan/projects/jrnl/tests/golden.jpg) +Lorem ipsum dolor sit amet, consectetur adipisicing elit, (/Volumes/dedan/bla.png) sed do eiusmod tempor incididunt ut (http://en.wikipedia.org/wiki/Generative_model) labore et dolore magna aliqua. Ut enim ad minim veniam, (/Users/dedan/projects/jrnl/tests/test_data/golden.jpg) quis C:\a\windows\file.png nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor http://www.dict.cc/?s=descendant in reprehenderit in voluptate velit esse /Volumes/dedan/test.png cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non (/Volumes/dedan/bla.blub) proident, sunt in culpa qui officia deserunt mollit anim id est laborum. diff --git a/tests/test_jrnl.py b/tests/test_jrnl.py index e86130c3..2e422891 100644 --- a/tests/test_jrnl.py +++ b/tests/test_jrnl.py @@ -20,10 +20,13 @@ class TestClasses(unittest.TestCase): "timeformat": "%Y-%m-%d %H:%M", "encrypt": False, "tagsymbols": "@", - "journal": "" + "journal": "", + "linewrap": 80, + "highlight": True } self.config['journal'] = os.path.join(self.test_data_path, 'empty.txt') self.journal = Journal(config=self.config) + self.journal.search_tags = '' def tearDown(self): shutil.rmtree(self.journal.data_path) @@ -36,6 +39,7 @@ class TestClasses(unittest.TestCase): self.assertEqual(len(os.listdir(self.journal.data_path)), 0) with open(os.path.join(self.test_data_path, 'url_test.txt')) as f: self.journal.new_entry(f.read()) + print str(self.journal) self.assertEqual(len(os.listdir(self.journal.data_path)), 1) def test_rendering_md(self): @@ -48,6 +52,7 @@ class TestClasses(unittest.TestCase): pass def test_pathsearch_regex(self): + # TODO: create pathes (als in url_test.txt) dynamically to work also in other locations true_positive = ['/Volumes/dedan/bla.png', '/Users/dedan/projects/jrnl/tests/test_data/golden.jpg', '/Volumes/dedan/test.png',