mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48: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
|
||||
pip-log.txt
|
||||
|
||||
.DS_Store
|
||||
|
|
|
@ -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,
|
||||
'' % (os.path.basename(im_path), random_name),
|
||||
body)
|
||||
return body
|
||||
|
||||
def new_entry(self, raw, date=None):
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Add table
Reference in a new issue