33import  re 
44from  pathlib  import  Path 
55from  textwrap  import  dedent 
6+ import  shutil 
67
78
89def  get_html_tags (string , start_tag = '>' , end_tag = '>' ):
@@ -53,7 +54,13 @@ def get_tags(string, start_tag, end_tag, include_tags=False):
5354
5455# find files to parse 
5556files  =  []
56- for  suffix  in  file_types .split (',' ):
57+ if  ','  in  file_types :
58+     file_types  =  file_types .split (',' )
59+ else :
60+     file_types  =  (file_types , )
61+ # print('file_types:', file_types) 
62+ 
63+ for  suffix  in  file_types :
5764    files .extend (list (path .glob ('*'  +  suffix )))
5865
5966files_to_ignore  =  []
@@ -72,7 +79,7 @@ def get_tags(string, start_tag, end_tag, include_tags=False):
7279    output_folder_path .mkdir ()
7380
7481# create css file 
75- with  open ( 'sswg.css' ,  'w' , encoding = 'utf-8' ) as  css_file :
82+ with  ( output_folder_path / 'sswg.css' ). open ( 'w' , encoding = 'utf-8' ) as  css_file :
7683    css_file .write (dedent (''' 
7784        html {max-width: 100%; margin: auto; color: #333333;} 
7885        h2 {font-size: 50px; margin-block-end:0px; margin-block-start:0px;} 
@@ -160,7 +167,7 @@ def get_tags(string, start_tag, end_tag, include_tags=False):
160167    current_font_style  =  'normal' 
161168    is_code_block  =  False 
162169    is_in_style_tag  =  False 
163-     inline_images  =  list () 
170+     inline_images  =  [] 
164171    code_block_id  =  0 
165172
166173    lines  =  text .split ('\n ' )
@@ -186,7 +193,10 @@ def get_tags(string, start_tag, end_tag, include_tags=False):
186193            with  open (target_document , 'r' , encoding = 'utf-8' ) as  file :
187194                headlines  =  [l .split ('## ' )[1 ].strip () for  l  in  file .readlines () if  l .strip ().startswith ('## ' )] # get name after ## 
188195                for  e  in  headlines :
189-                     link  =  target_document .replace ('.txt' , '.html' ) +  f'#{ e }  
196+                     link  =  target_document 
197+                     for  suffix  in  file_types :
198+                         link  =  link .replace (suffix , '.html' )
199+                     link  =  f'{ link } { e }  
190200                    new_lines .append (current_indent  +  f'• <a href="{ link } { e }  )
191201
192202        elif  l .startswith ('```' ):
@@ -410,3 +420,11 @@ def get_tags(string, start_tag, end_tag, include_tags=False):
410420    with  open (output_folder_path  /  f'{ target_file .stem }  , 'w' , encoding = 'utf-8' ) as  text_file :
411421        text_file .write (new_text )
412422        print ('finished building:' , target_file .stem  +  '.html' )
423+ 
424+ 
425+     # # if using output_folder, copy images over 
426+     # if output_folder_path != '.': 
427+     #     for img_name in inline_images: 
428+     #         print('--------- copy over image:', img_name) 
429+     #         # copy file to folder 
430+     #         shutil.copy(path/img_name, output_folder_path/img_name) 
0 commit comments