3
3
# pylint: disable=import-error
4
4
from requests import Response
5
5
6
-
7
6
from bookstack_file_exporter .exporter .node import Node
8
7
from bookstack_file_exporter .archiver import util as archiver_util
9
8
from bookstack_file_exporter .config_helper .config_helper import ConfigNode
10
9
from bookstack_file_exporter .common import util as common_util
11
10
12
-
13
11
_META_FILE_SUFFIX = "_meta.json"
14
12
_TAR_SUFFIX = ".tar"
15
13
_TAR_GZ_SUFFIX = ".tgz"
26
24
"tgz" : _TAR_GZ_SUFFIX
27
25
}
28
26
29
-
30
27
_IMAGE_DIR_NAME = "images"
31
- # _MARKDOWN_IMAGE_REGEX= re.compile(r"\[\!\[^$|.*\].*\]")
32
28
_MARKDOWN_STR_CHECK = "markdown"
33
29
34
30
class ImageNode :
@@ -54,13 +50,16 @@ def _get_image_name(self) -> str:
54
50
55
51
@property
56
52
def image_relative_path (self ):
53
+ """return image path local to page directory"""
57
54
return self ._image_relative_path
58
55
59
56
@property
60
57
def markdown_str (self ):
58
+ """return markdown url str to replace"""
61
59
return self ._markdown_str
62
-
60
+
63
61
def set_markdown_content (self , img_details : Dict [str , Union [int , str ]]):
62
+ """provide image metadata to set markdown properties"""
64
63
self ._markdown_str = self ._get_md_url_str (img_details )
65
64
66
65
@staticmethod
@@ -121,7 +120,6 @@ def _archive_page(self, page: Node, export_format: str, data: bytes,
121
120
image_nodes : List [ImageNode ] = None ):
122
121
page_file_name = f"{ self .archive_base_path } /" \
123
122
f"{ page .file_path } /{ page .name } { _FILE_EXTENSION_MAP [export_format ]} "
124
- # not yet implemented
125
123
if self .modify_md and export_format == _MARKDOWN_STR_CHECK and image_nodes :
126
124
data = self ._update_image_links (data , image_nodes )
127
125
self .write_data (page_file_name , data )
@@ -176,12 +174,12 @@ def _update_image_links(self, page_data: bytes, image_nodes: List[ImageNode]) ->
176
174
img_meta_url = f"{ self .api_urls ['images' ]} /{ img_node .id } "
177
175
img_details = common_util .http_get_request (img_meta_url ,
178
176
self ._headers , self .verify_ssl )
179
-
180
177
img_node .set_markdown_content (img_details .json ())
181
178
if not img_node .markdown_str :
182
179
continue
183
180
# 1 - what to replace, 2 - replace with, 3 is the data to replace
184
- page_data = re .sub (img_node .markdown_str .encode (), img_node .image_relative_path ().encode (), page_data )
181
+ page_data = re .sub (img_node .markdown_str .encode (),
182
+ img_node .image_relative_path .encode (), page_data )
185
183
return page_data
186
184
187
185
@property
0 commit comments