mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-12 01:18:31 +02:00
replace the original image name by markdown syntax for an inline image
This commit is contained in:
parent
a1d14a71dd
commit
2813607181
4 changed files with 15 additions and 3 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -20,3 +20,5 @@ lib64
|
||||||
|
|
||||||
# Installer logs
|
# Installer logs
|
||||||
pip-log.txt
|
pip-log.txt
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
|
|
@ -251,7 +251,7 @@ class Journal:
|
||||||
|
|
||||||
def parse_for_images(self, body):
|
def parse_for_images(self, body):
|
||||||
# TODO: parse also for name (like used in markdown [name](url))
|
# TODO: parse also for name (like used in markdown [name](url))
|
||||||
|
found_images = []
|
||||||
for word in body.split():
|
for word in body.split():
|
||||||
res = self.path_search.match(word)
|
res = self.path_search.match(word)
|
||||||
if res and os.path.exists(res.groups()[0]):
|
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]
|
ext = os.path.splitext(os.path.basename(im_path))[1]
|
||||||
random_name = 'img_' + self._random_string() + ext
|
random_name = 'img_' + self._random_string() + ext
|
||||||
shutil.copyfile(im_path, os.path.join(self.data_path, random_name))
|
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,
|
||||||
|
'' % (os.path.basename(im_path), random_name),
|
||||||
|
body)
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def new_entry(self, raw, date=None):
|
def new_entry(self, raw, date=None):
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
ein normalser satz.
|
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
|
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.
|
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.
|
||||||
|
|
|
@ -20,10 +20,13 @@ class TestClasses(unittest.TestCase):
|
||||||
"timeformat": "%Y-%m-%d %H:%M",
|
"timeformat": "%Y-%m-%d %H:%M",
|
||||||
"encrypt": False,
|
"encrypt": False,
|
||||||
"tagsymbols": "@",
|
"tagsymbols": "@",
|
||||||
"journal": ""
|
"journal": "",
|
||||||
|
"linewrap": 80,
|
||||||
|
"highlight": True
|
||||||
}
|
}
|
||||||
self.config['journal'] = os.path.join(self.test_data_path, 'empty.txt')
|
self.config['journal'] = os.path.join(self.test_data_path, 'empty.txt')
|
||||||
self.journal = Journal(config=self.config)
|
self.journal = Journal(config=self.config)
|
||||||
|
self.journal.search_tags = ''
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.journal.data_path)
|
shutil.rmtree(self.journal.data_path)
|
||||||
|
@ -36,6 +39,7 @@ class TestClasses(unittest.TestCase):
|
||||||
self.assertEqual(len(os.listdir(self.journal.data_path)), 0)
|
self.assertEqual(len(os.listdir(self.journal.data_path)), 0)
|
||||||
with open(os.path.join(self.test_data_path, 'url_test.txt')) as f:
|
with open(os.path.join(self.test_data_path, 'url_test.txt')) as f:
|
||||||
self.journal.new_entry(f.read())
|
self.journal.new_entry(f.read())
|
||||||
|
print str(self.journal)
|
||||||
self.assertEqual(len(os.listdir(self.journal.data_path)), 1)
|
self.assertEqual(len(os.listdir(self.journal.data_path)), 1)
|
||||||
|
|
||||||
def test_rendering_md(self):
|
def test_rendering_md(self):
|
||||||
|
@ -48,6 +52,7 @@ class TestClasses(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_pathsearch_regex(self):
|
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',
|
true_positive = ['/Volumes/dedan/bla.png',
|
||||||
'/Users/dedan/projects/jrnl/tests/test_data/golden.jpg',
|
'/Users/dedan/projects/jrnl/tests/test_data/golden.jpg',
|
||||||
'/Volumes/dedan/test.png',
|
'/Volumes/dedan/test.png',
|
||||||
|
|
Loading…
Add table
Reference in a new issue