@@ -40,29 +40,27 @@ def my_get(url, **kwargs):
40
40
41
41
# Kindly provided by our friend WizardLM-30B
42
42
def my_open (* args , ** kwargs ):
43
- """
44
- Custom open function that modifies the file contents before returning.
45
- """
46
43
filename = str (args [0 ])
47
44
if filename .endswith ("index.html" ):
48
45
with original_open (* args , ** kwargs ) as f :
49
46
file_contents = f .read ()
50
47
48
+ file_contents = file_contents if isinstance (file_contents , str ) else file_contents .decode ('utf-8' )
51
49
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
+ ''
54
52
)
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" )
56
54
file_contents = file_contents .replace (
57
55
'</head>' ,
58
56
'\n <script src="file/js/katex/katex.min.js"></script>'
59
57
'\n <script src="file/js/katex/auto-render.min.js"></script>'
60
58
'\n <script src="file/js/highlightjs/highlight.min.js"></script>'
61
59
'\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">'
63
60
'\n <script>hljs.addPlugin(new CopyButtonPlugin());</script>'
64
61
'\n </head>'
65
62
)
63
+ file_contents = file_contents .encode ('utf-8' )
66
64
67
65
return io .BytesIO (file_contents ) # return bytes
68
66
else :
0 commit comments