31
31
32
32
33
33
class md_to_html_SimpleHTTPRequestHandler (SimpleHTTPRequestHandler ):
34
- def __init__ (self , * args , MarkdownIt_obj = None , css_file = None , ** kwargs ):
34
+ def __init__ (self , * args , MarkdownIt_obj = None , css_file = None , live_md_rr = False , ** kwargs ):
35
35
self .MarkdownIt_obj = MarkdownIt_obj
36
36
self .css_file = css_file
37
+ self .live_md_rr = live_md_rr
37
38
super ().__init__ (* args , ** kwargs )
38
39
39
40
40
41
def do_GET (self , rm_temp_html = False ):
41
42
"""Serve a GET request."""
42
43
self .url_dc_path = urllib .parse .unquote (urllib .parse .urlsplit (self .path ).path ) # url decode, strip query params for file check
43
- if self .url_dc_path .endswith (".md" ) and os .path .exists (os .path .join (self .directory , f".{ self .url_dc_path } " )): # check for markdown file request
44
+ if self .MarkdownIt_obj and self . url_dc_path .endswith (".md" ) and os .path .exists (os .path .join (self .directory , f".{ self .url_dc_path } " )): # check for markdown file request
44
45
in_file_path = os .path .join (self .directory , f".{ self .url_dc_path } " )
45
46
out_file_path = os .path .join (self .directory , f".{ os .path .splitext (self .url_dc_path )[0 ]} .html" )
46
47
md_to_html .markdown_to_html (
47
48
self .MarkdownIt_obj ,
48
49
in_file_path = in_file_path ,
49
50
out_file_path = out_file_path ,
50
- css_file = self .css_file )
51
+ css_file = self .css_file ,
52
+ live_md_rr = self .live_md_rr )
51
53
self .path = f"{ os .path .splitext (self .path )[0 ]} .html"
52
54
rm_temp_html = True
53
55
f = self .send_head ()
@@ -73,6 +75,8 @@ def do_GET(self, rm_temp_html=False):
73
75
'[default:current directory]' )
74
76
parser .add_argument ('--css_file' , default = None ,
75
77
help = 'css-file-path; its content will be written to the <style> element' )
78
+ parser .add_argument ('--live_md_rr' , '-l' , action = 'store' , type = int , default = None ,
79
+ help = 'continuous refresh rate of MD page, in ms' )
76
80
parser .add_argument ('port' , action = 'store' ,
77
81
default = 8000 , type = int ,
78
82
nargs = '?' ,
@@ -83,11 +87,12 @@ def do_GET(self, rm_temp_html=False):
83
87
else :
84
88
MarkdownIt_obj = MarkdownIt ("commonmark" ).enable ("table" ).enable ("strikethrough" )
85
89
if args .css_file and not os .path .isfile (args .css_file ):
86
- raise FileNotFoundError (f"looks like the given `css_file` argument's value - { args .css_file } - is not actually a file " )
90
+ raise FileNotFoundError (f"looks like the given `css_file` argument's value - { args .css_file } - cannot be found " )
87
91
handler_class = partial (md_to_html_SimpleHTTPRequestHandler ,
88
92
directory = args .directory ,
89
93
MarkdownIt_obj = MarkdownIt_obj ,
90
- css_file = args .css_file )
94
+ css_file = args .css_file ,
95
+ live_md_rr = args .live_md_rr )
91
96
92
97
# ensure dual-stack is not disabled; ref #38907
93
98
class DualStackServer (ThreadingHTTPServer ):
0 commit comments