From 5ca8cdb66896b46791e08bb8200d2f8bdf409e33 Mon Sep 17 00:00:00 2001 From: Leopold Talirz Date: Tue, 16 Nov 2021 23:26:12 +0100 Subject: [PATCH] display images inline Images were only linked, not displayed inline --- N2Omodule.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/N2Omodule.py b/N2Omodule.py index f8147b4..b10d6b3 100644 --- a/N2Omodule.py +++ b/N2Omodule.py @@ -184,7 +184,7 @@ def embedded_link_convert(line): # folder style links #regexPath = compile("^\[(.+)\]\(([^\(]*)(?:\.md|\.csv)\)$") # Overlap incase multiple links in same line - #regexRelativePathImage = compile("(?:\.png|\.jpg|\.gif|\.bmp|\.jpeg|\.svg)") + regexRelativePathImage = compile("(?:\.png|\.jpg|\.gif|\.bmp|\.jpeg|\.svg)") regexPath = compile("!\[(.*?)\]\((.*?)\)") regex20 = compile("%20") @@ -197,7 +197,7 @@ def embedded_link_convert(line): # modify paths into local links. just remove UID and convert spaces Title = pathMatch.group(1) relativePath = pathMatch.group(2) - #is_image = regexRelativePathImage.search(relativePath) + is_image = regexRelativePathImage.search(relativePath) regexSpecialUtf8 = compile("%([A-F0-9][A-F0-9])%([A-F0-9][A-F0-9])%([A-F0-9][A-F0-9])") regexutf8 = compile("%([A-F0-9][A-F0-9])%([A-F0-9][A-F0-9])") @@ -236,7 +236,10 @@ def embedded_link_convert(line): else: relativePath = regexutf8.sub(unicode_str, relativePath, 1) - line, num_matchs = regexPath.subn("[["+relativePath+"]]", line) + if is_image: + line, num_matchs = regexPath.subn("![["+relativePath+"]]", line) + else: + line, num_matchs = regexPath.subn("[["+relativePath+"]]", line) if num_matchs > 1: print(f"Warning: {line} replaced {num_matchs} matchs!!") @@ -347,4 +350,4 @@ def N2Omd(mdFile): return newLines, [in_link_cnt, em_link_cnt, bl_link_cnt,tags_cnt] - \ No newline at end of file +