@@ -40,29 +40,27 @@ def my_get(url, **kwargs):
4040
4141# Kindly provided by our friend WizardLM-30B
4242def my_open (* args , ** kwargs ):
43- """
44- Custom open function that modifies the file contents before returning.
45- """
4643 filename = str (args [0 ])
4744 if filename .endswith ("index.html" ):
4845 with original_open (* args , ** kwargs ) as f :
4946 file_contents = f .read ()
5047
48+ file_contents = file_contents if isinstance (file_contents , str ) else file_contents .decode ('utf-8' )
5149 file_contents = file_contents .replace (
52- b '\t \t <script\n \t \t \t src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.9/iframeResizer.contentWindow.min.js"\n \t \t \t async\n \t \t ></script>' ,
53- b ''
50+ '\t \t <script\n \t \t \t src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.9/iframeResizer.contentWindow.min.js"\n \t \t \t async\n \t \t ></script>' ,
51+ ''
5452 )
55- file_contents = file_contents .replace (b "cdnjs.cloudflare.com" , b "127.0.0.1" )
53+ file_contents = file_contents .replace ("cdnjs.cloudflare.com" , "127.0.0.1" )
5654 file_contents = file_contents .replace (
5755 '</head>' ,
5856 '\n <script src="file/js/katex/katex.min.js"></script>'
5957 '\n <script src="file/js/katex/auto-render.min.js"></script>'
6058 '\n <script src="file/js/highlightjs/highlight.min.js"></script>'
6159 '\n <script src="file/js/highlightjs/highlightjs-copy.min.js"></script>'
62- f'\n <link id="highlight-css" rel="stylesheet" href="file/css/highlightjs/{ "github-dark" if shared .settings ["dark_theme" ] else "github" } .min.css">'
6360 '\n <script>hljs.addPlugin(new CopyButtonPlugin());</script>'
6461 '\n </head>'
6562 )
63+ file_contents = file_contents .encode ('utf-8' )
6664
6765 return io .BytesIO (file_contents ) # return bytes
6866 else :
0 commit comments